Flo Cp
Flo Cp

Reputation: 351

Requests prepare url, value wrong

I use prepare() from Request to prepare the url before sending my request. But the value returned by the function is not correct. Like you can see this for the parameters codif= I send a list of values, and the result must be codif=7,110 but requests return me this codif%3D=7%2C110 and in fact is not work.

Do you have any idea to solve this?

from requests import Request

dict_data = {
    'note':['716'],
    'codif':[7, 110]}

request_parameters = {
                'note=' : dict_data['note'],
                'codif=' : ','.join([str(i) for i in dict_data['codif']]),
            }
p = Request('GET', "https://test.intranert.com/api/light?", params=request_parameters).prepare()
p.url

Output : 'https://test.intranert.com/api/light?note%3D=716&codif%3D=7%2C110'

Expectation : 'https://test.intranert.com/api/light?note=716&codif=7,110'

Thank you,

Upvotes: 0

Views: 650

Answers (1)

Nastor
Nastor

Reputation: 638

That would be because the browser encodes URL input by its hexadecimal representation in ASCII table keycodes. Take a look at this: as you can see, the hex for the comma is 2C, so it is fine.

Upvotes: 1

Related Questions