data = {
‘content’:‘敏感词’
}
headers = {‘Content-Type’: ‘application/json;charset=utf-8’}
push_url = ‘https://api.weixin.qq.com/wxa/msg_sec_check?access_token={}’.format(access_token)
checkMsg = requests.post(push_url, headers=headers, data=json.dumps(data).encode(‘utf-8’))
if json.loads(checkMsg.text)[‘errcode’]!=0:
raise Exception(‘内容含有违法违规内容’)
请问 哪里出了问题?
自己解决了 是编码问题 看了json.dumps的源码默认是ascii
贴出代码:
access_token = getAccessToken()
data = {
“content”:v_comment.encode(“utf-8”).decode(“latin1”)
}
headers = {‘content-type’: ‘application/json’}
push_url = ‘https://api.weixin.qq.com/wxa/msg_sec_check?access_token={}’.format(access_token)
checkMsg = requests.post(push_url, data=json.dumps(data,ensure_ascii=False),headers=headers)