is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.
問題指明:post請求中文,無法進行編碼,需要對參數進行“utf-8”的編碼
嘗試:按報錯進行解決:
response=requests.request("POST", url, data=payload.encode("utf-8"), headers=headers)
出現問題:返回的response的中文數據為亂碼:

中文亂碼
相當亂碼的話,應該是編碼不匹配的問題,嘗試解決:
print(response.text.encode("utf-8"))
結果這亂碼更加摸不著頭腦了:

encode("utf-8")亂碼
這個問題,一直弄了我一個晚上,太困睡覺,起床后,直到這篇解決我的問題:python 設置requests 編碼,完美解決中文亂碼問題:
response.enconding="utf-8"
print(response.text)
拓展:特別注意-requests的請求頭header,一些設置編碼的參數問題:
請求頭:header:
'accept-encoding': "gzip, deflate, br",
這個請求頭直接印象下面亂碼:

image.png
解決分析參考: 從python爬蟲引發(fā)出的gzip,deflate,sdch,br壓縮算法分析
就因為這個,讓我弄了一晚,得到的經驗是:在測試bug的時候,盡量減少變量,能不要的,就不要。
參考
- Python 爬蟲 (requests) 發(fā)送中文編碼的 HTTP POST 請求:整個問題的解決流程;
-
解決 python3 requests headers 參數不能有中文:這個有參考意義,但要注意是
header還是body