I am sending the second string via post (JavaScript) to my bootle server (Python):
query = {
'wiki': 'Tr%E1%BA%A7n_H%C6%B0ng_%C4%90%E1%BA%A1o',
'uid':'f17afd66aae3a'
}
$.post(url, query, function(data, status){}):
But when I print what I get from the post it gives the following result:
b'uid=f17afd66aae3a&wiki=Tr%25E1%25BA%25A7n_H%25C6%25B0ng_%25C4%2590%25E1%25BA%25A1o'
- First print
In the case I make two split transforming this binary string into a dictionary through the function translate(postdata)
.
{'uid': 'f17afd66aae3a', 'wiki': 'Tr%25E1%25BA%25A7n_H%25C6%25B0ng_%25C4%2590%25E1%25BA%25A1o'}
- Second print
And as my code will access the wikipedia article with such name:
https://en.wikipedia.org/wiki/Tr%E1%BA%A7n_H%C6%B0ng_%C4%90%E1%BA%A1o
I can not access it because my request has the following url:
https://en.wikipedia.org/wiki/Tr%25E1%25BA%25A7n_H%25C6%25B0ng_%25C4%2590%25E1%25BA%25A1o
That generates an error because the page does not exist.
There's my code in the bottle:
@post('/update_article')
@enable_cors
def update_article_post():
token = request.cookies.get('token', '0')
if load_token(token):
postdata = request.body.read()
print(postdata)
dici = translate(postdata)
print(dici)
# res = update_article(dici['uid'], dici['wiki'])
# return {'data': res}
else:
return redirect('/login.html')
Is there any way to get the post the right way, or code this string?