首页 > 编程语言 >Python requests.post 发送中文 'latin-1' codec can't encode characters in position 57-62:

Python requests.post 发送中文 'latin-1' codec can't encode characters in position 57-62:

时间:2022-12-16 11:34:10浏览次数:57  
标签:Use utf json 62 encode False post data

 headers = {"Content-type": "application/json;charset=utf-8", "Authorization": "bearer " + token}
    data = {
        # 上游任务id名称
        'upstreamTaskId': taskid,
        'processTaskName': taskname,
        'processTaskDesc': processTaskDesc,
        'masterDataId': 2,
        'requestType': 1,
        'processGroupDataList': processGroupDataList
    }
    data = json.dumps(data, ensure_ascii=False)
    response = requests.post(url, data=data, headers=headers, timeout=600, verify=False).content.decode('utf8')

报错:Python requests.post 发送中文 'latin-1' codec can't encode characters in position 57-62: Body ('元素认知服务') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.

 

data = json.dumps(data, ensure_ascii=False)改成
data = json.dumps(data, ensure_ascii=False).encode("utf-8")

标签:Use,utf,json,62,encode,False,post,data
From: https://www.cnblogs.com/shaosks/p/16986898.html

相关文章