Skip to content
Snippets Groups Projects
Commit b8a0d209 authored by Enzo Simonnet's avatar Enzo Simonnet
Browse files

gestion de l'encodage des caractères utf-8 dans l'url des requêtes curl

parent 4abb783c
No related branches found
No related tags found
No related merge requests found
from flask import Flask, Response, json, jsonify, request
from flask_cors import CORS
from urllib.parse import unquote
import requests
# import sys
# import codecs
# sys.stdout = codecs.getwriter('utf-8')(sys.stdout.buffer, 'strict')
import config
from wiktextract_wrapper import Wiktextract
......@@ -28,6 +34,9 @@ def index():
@app.route("/simplesearch/<lang>/<word>", methods=["GET"])
def search(lang, word):
word = requests.utils.unquote(word)
word = word.encode('latin-1').decode('utf-8') # Decode the word from Latin-1 to UTF-8
# print(word)
if lang not in config.supported_wiktlangs:
return jsonify({"error": f"Language {lang} not supported"}), 400
......@@ -55,8 +64,11 @@ def search(lang, word):
if wiktextractor.wxr.thesaurus_db_conn:
wiktextractor.wxr.thesaurus_db_conn.close()
@app.route("/search/<wiktlang>/<wordlang>/<word>/<format>", methods=["GET"])
@app.route("/search/<wiktlang>/<wordlang>/<path:word>/<format>", methods=["GET"])
def search_and_format(wiktlang, wordlang, word, format):
word = requests.utils.unquote(word)
word = word.encode('latin-1').decode('utf-8') # Decode the word from Latin-1 to UTF-8
# print(word)
# app.logger.info('Received a request from /search/<wiktlang>/<wordlang>/<word>/<format>')
if wiktlang not in config.supported_wiktlangs:
return jsonify({"error": f"Language {wiktlang} not supported"}), 400
......@@ -64,7 +76,7 @@ def search_and_format(wiktlang, wordlang, word, format):
if len(format)>2 and format[0:2] in ("a_", "A_"):
ascii = True
format = format[2:]
print(ascii, format)
# print(ascii, format)
else:
ascii = False
try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment