Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
365 views
in Technique[技术] by (71.8m points)

api - Python requests adding quotes around parameters, causing GET failure

headers = {"accept": "application/json",
           "key": "someSecretKey",
           'User-Agent': None, 
           'Connection': None, 
           'Accept-Encoding': None}
url=r'https://something.something'
idVar='id_123'
r = requests.get(url, headers=headers, params={'id': idVar})

if I send this straight up, the url I get upon debugging is:

https://something.something?id=%22id_123%22

which causes a 404 error with the API. I confirmed this by using curlify to generate a curl string to use in terminal.

The issue is fixed when I do a .replace('%22','') on the curlify string to get the following url which does work when using curl!!

https://something.something?id=id_123

I guess the API service must be resilient to this. But in the meantime, how do tell requests library to not add the quote markers in the url string?

question from:https://stackoverflow.com/questions/65931886/python-requests-adding-quotes-around-parameters-causing-get-failure

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...