简体   繁体   中英

Python3 Requests Error/Unicode Error

I've come across an error in requests, it's confusing me a lot and I do not know what is causing it, any help would be very appreciated!

https://pastebin.com/VWYYMPBR (had to use pastebin as it would not let me post the error)

problem is with in line response = session.post(url, data=payload)

payload contains unicode char \… which can't be encoded with 'latin-1'

Example

when we encode "\…" with "latin-1" it can't be encoded but we can encode it with "utf-8":

 >>> a="\…" >>> a.encode('latin-1') Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeEncodeError: 'latin-1' codec can't encode character '\…' in position 0: ordinal not in range(256) >>> a.encode('utf-8') b'\\xe2\\x80\\xa6' 

possible fix is

. encode your payload with 'utf-8

eg response = session.post(url, data=payload.encode("utf-8"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM