{"errcode":40033,"errmsg":"invalid charset. please check your request, if include

时间:2023-02-25 13:57:50


问题

​{"errcode":40033,"errmsg":"invalid charset. please check your request, if include \\uxxxx will create fail! hint: [FISJMa0799shc2]"}​

解决方案:

最重要的一句话:

json.dumps(parameters, ensure_ascii=False).encode('utf-8')

完整代码如下

urlstr = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + access_token
parameters = {
"button":[
{
"type": "scancode_push",
"name": "扫码打印",
"key": "rselfmenu_0_1",
"sub_button": [ ]
},
{
"name":"个人中心",
"sub_button":[
{
"type":"view",
"name":"我的订单",
"url":"https://injiajia.telabytes.com/"
},
{
"type":"view",
"name":"在校兼职",
"url":"https://injiajia.telabytes.com/"
}
]
}]
}
param_jsonstr = json.dumps(parameters, ensure_ascii=False).encode('utf-8')
http = urllib3.PoolManager()
response = http.request("POST",
urlstr,
headers={'Content-Type' : 'application/json'},
body=param_jsonstr)
resp_data = str(response.data, encoding="utf-8")
print(resp_data)