Python - 处理 requets 请求接口时, 传输中文数据乱码问题

 

# 使用  ensure_ascii=False 

data = {
    'name': '测试名称'
}

url = "https://api.weixin.qq.com/xxx/"

data = json.dumps(data, ensure_ascii=False)

headers = {'content-type': 'application/json;charset=utf-8'}
response = requests.post(url, data=data.encode('utf-8'), headers=headers)
res = json.loads(response.text)

 

posted @ 2022-08-30 18:34  _Q  阅读(137)  评论(0编辑  收藏  举报