I am having an issue converting some simple get request code from Python 2 to 3. Running the same code with same version of requests (2.25.1) I get different response headers as well as content. Using Py2, I get content/text properly. However the with same code in Py3 I get garbled content/text. Is there a difference in how Py3 handles a get request??
response = requests.get(url)
print (response.headers)
print (response.text)
Header response, Py2 vs 3. Note some proprietary data was removed from the Py2 header. Data does not appear in Py3 header.
{'X-Powered-By': 'ASP.NET', 'Transfer-Encoding': 'chunked', 'Content-Encoding': 'gzip', 'Vary': 'Accept-Encoding', 'Connection': 'close', 'Date': 'Tue, 26 Jan 2021 16:36:11 GMT', 'Server': 'Microsoft-IIS/6.0', 'Content-Type': 'text/plain; charset=utf-8' }
{'Connection': 'close', 'Date': 'Tue, 26 Jan 2021 16:36:16 GMT', 'Content-Type': 'text/plain; charset=utf-8', 'Server': 'Microsoft-IIS/6.0'}
Example py3 content.
a
▼ ?
408
?Ao?8?????V.??BI???B?.????????V??♀??N???Z???N)??n??]?U2L?~?↓????♀?aX??%p?2?????????;?(?`5???k,HFS9???????n??
I have tried to .encode('utf-8') the response.text but I get a string like
a
x1fxefxbfxbdx08x00x00
Why is there a difference between the same request in different versions of python?
question from:
https://stackoverflow.com/questions/65905655/requests-different-data-between-python-2-vs-python-3 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…