Closed bbbcs closed 5 years ago
Python 3.6.2 python-weixin==0.4.3
把数据使用 smart_bytes 转码一下试试?
找到问题了
def params_encoding(params, charset='utf-8'):
newparams = {}
for k, v in params.items():
newparams[k] = smart_unicode(v)
return newparams
这里key还是byte的,所以后面xmltodict 匹配attitude的时候 key startwith('@')的时候出错了 。。
python3字符串处理逻辑和python2不太一样,改成: newparams[k.decode("utf-8")] = smart_unicode(v) 就好了。
签名拼字符串的地方也要改一下: prestr += '%s=%s%s' % (k.decode('utf-8'), newparams[k].decode('utf-8'), delimiter)
感谢 反馈 我测试一下加进去
同遇到该问题
支付调用统一支付接口的时候,我基本上只填了最基本的信息 ,不知道哪里出的问题。
File "/Users/ /lib/python3.6/site-packages/weixin/pay.py", line 464, in unifiedorder method, url, kwargs = self.prepare_request('POST', path, params) File "/Users/ /lib/python3.6/site-packages/weixin/pay.py", line 115, in prepare_request kwargs['data'] = smart_bytes(xmltodict.unparse(xml_dict)) File "/Users/ /lib/python3.6/site-packages/xmltodict.py", line 449, in unparse kwargs) File "/Users/ ** /lib/python3.6/site-packages/xmltodict.py", line 386, in _emit if ik.startswith(attr_prefix): TypeError: startswith first arg must be bytes or a tuple of bytes, not str