У меня есть код:
def fil(method):
if method == "censure":
if request.method == 'POST':
json = request.json
if 'access_token' in json and json['access_token'] == "bi83xs.T.ajdsjckfjs03@34095":
if 'text' in json and 'lang' in json:
check_res = check_censur(json['text'], json['lang'])
print(check_res[1])
res = { "response": { "checkable_text": json['text'], "matches": [ check_res[1] ] }}
return res
else:
err = { "error": { "error_code": 3, "error_text": "One of parametr is empty or invalid (lang, text)" } }
return err
else:
if not 'access_token' in json:
errr = { "error": { "error_code": 4, "error_msg": "User authorization failed: no access_token passed" } }
else:
errr = { "error": { "error_code": 5, "error_msg": "User authorization failed: invalid access_token" } }
return errr
else:
err = { "error": { "error_code": 2, "error_msg": "Your method is not allowed! Use POST!"} }
return err
else:
err = { "error": { "error_code": 404, "error_msg": "Unknown method" } }
return err
При запросе:
POST http://127.0.0.1:5000/devtools/censure
content-type: application/json;
{
"access_token": "bi83xs.T.ajdsjckfjs03@34095",
"text": "тут плохое слово",
"lang": "ru"
}
Возвращается строка:
{
"response": {
"checkable_text": "\u0435\u0431\u043b\u0430\u043d",
"matches": [
"\u0435\u0431\u043b\u0430\u043d"
]
}
}