收藏
回答

python 自定义菜单? 'errcode': 40033

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'}


回答关注问题邀请回答
收藏

1 个回答

  • 余生
    余生
    2023-12-12
    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)
    
    
    
    2023-12-12
    有用
    回复
登录 后发表内容