POST提交时总是报错:
{"errcode":40017,"errmsg":"invalid button type"}
最后查出来是由于数据中有中文引起的
解决:
data = {"button":[
{"name": u"会员服务",
"sub_button":[
{"type":"click","name":u"健康咨询","key":"JKZX"},
]
},
{"name":u"申请加入","sub_button":[
{"type":"view","name":u"企业入会申请","url": ""},
]
},
{"type":"view","name":u"关于","url":""}
]
}
url = ‘https://api.weixin.qq.com/cgi-bin/menu/create?access_token=。。。‘
data = simplejson.dumps(data, ensure_ascii=False).encode(‘utf-8‘)
#加上参数ensure_ascii=False 后 提交的数据中的中文就不会再被转码,然后再编下UTF-8
print data
req = urllib2.Request(url)
req.add_header(‘Content-Type‘, ‘application/json‘)
req.add_header(‘encoding‘, ‘utf-8‘)
response = urllib2.urlopen(req, data)
result = response.read()
print result
微信公众号接口添加菜单时错误(errcode":40017 invalid button type),布布扣,bubuko.com
微信公众号接口添加菜单时错误(errcode":40017 invalid button type)
原文:http://my.oschina.net/zuoan001/blog/304867