Decryption error in request

Asked

Viewed 32 times

0

I am sending the segiunte string via post (Javascript) to my server Bootle(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 gives the following result:

b'uid=f17afd66aae3a&wiki=Tr%25E1%25BA%25A7n_H%25C6%25B0ng_%25C4%2590%25E1%25BA%25A1o' - First print

In case I do 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 how 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’t 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

Which generates an error because there is no page.

There’s my code on 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 receive the post the right way, or encode that string?

2 answers

1

try coding with Base64

dai on the Python server try to decode the string before playing on the wiki, use the Python b64decode

import base64
Request = 'cmVzcG9zdGEgZGVjb2RpZmljYWRhIA==' 
resposta = base64.b64decode(Request)
print(resposta)

the sera exit

resposta decodificada 

1


According to the bottle documentation it is possible to access the parameters received from a POST using request.forms.get('campo').

So your question seems to be solved with the code:

wiki = request.forms.get('wiki')

If Bottle does not do the automatic Decode of the string you can use the method urlli.parse.unquote().

from urllib.parse import unquote

print(unquote('Tr%25E1%25BA%25A7n_H%25C6%25B0ng_%25C4%2590%25E1%25BA%25A1o'))
# Saída: Trần_Hưng_Đạo

Browser other questions tagged

You are not signed in. Login or sign up in order to post.