url = f"https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token={access_token}"
jsonmenu ={
"button": [{
"type": "click",
"name": "开发指引",
"key": "mpGuide"
},
{
"name": "公众平台",
"sub_button": [{
"type": "view",
"name": "大闸蟹",
"url": ""
}]
},
{
"type": "click",
"name": "周末天气",
"key": "week"
}
]
}
jsonmenu = json.dumps(jsonmenu, ensure_ascii=False).encode("utf-8")
headers = {'Content-Type': 'application/json; charset=utf-8'}
result = requests.post(url, json=jsonmenu,headers=headers).text
print("menuid", json.loads(result))
永远返回的是
{'errcode': 40033, 'errmsg': 'invalid charset. please check your request, if include \\uxxxx will create fail! rid: 657829d3-6b5a9be4-7b7f360a'}
import json import requests url = f"https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token={access_token}" jsonmenu = { "button": [{ "type": "click", "name": "开发指引", "key": "mpGuide" }, { "name": "公众平台", "sub_button": [{ "type": "view", "name": "大闸蟹", "url": "" }] }, { "type": "click", "name": "周末天气", "key": "week" }] } headers = {'Content-Type': 'application/json; charset=utf-8'} result = requests.post(url, json=jsonmenu, headers=headers).json() # 直接使用 .json() 解析 JSON 响应 print("menuid", result)