python - how to convert response to image with decoding? - Stack Overflow

I was using this code on python previouslywith open(f"image.jpg", "wb") as fh:fh.w

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745672210a4639473.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信