UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 19-31: ordinal not in range(128)

在Python中重设UTF-8编码输出

在脚本中加入

1
2
3
import sys
import codecs
sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())

UnicodeEncodeError: ‘latin-1’ codec can’t encode characters in position 19-31: Body (‘’) is not valid Latin-1. Use body.encode(‘utf-8’) if you want to send it encoded in UTF-8.”

requests模块报错

是因为传入的data数据未处理引起的

在请求参数后加.encode('utf-8')

1
res = requests.post(url, headers=self.headers, data=payload.encode('utf-8')).json()