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.

 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")
或者data = json.dumps(data)
posted on 2022-12-16 11:28  shaomine  阅读(2116)  评论(0编辑  收藏  举报