admin管理员组

文章数量:1435859

I was using this code on python previously

with open(f"image.jpg", "wb") as fh:
    fh.write(response.content)

and it was working fine, but now I changed lib for requests and the current script doesn't work

That is the new response.text example

while old response.text looks like:

tried this code to decode unicode:

with open(f"image.jpg", "wb") as fh:
    fh.write(response.text.encode().decode('unicode_escape').encode())

but the image is not correct, it does not display.

also tried: ee = base64.encodebytes(rim.content[1:-1].decode('unicode_escape').replace('\\n','').replace('\n','').replace('\\r','').replace('\r','').encode())

and as result got:

I did consider replacing all slashes and \n but still the result string is invalid. I believe there are some decode errors or my mistakes.

I use the same headers for content type and encoding in the request, so please, if it's possible, suggest solutions not related to the request itself.

本文标签: pythonhow to convert response to image with decodingStack Overflow