在做 企业向微信用户个人付款  功能时,调用第三方sdk,在 进行 requests 的post请求时,

代码如下

req = requests.post(url, data=data,cert(api_client_cert_path, api_client_key_path),)

报错如下

Traceback (most recent call last):
File "G:\FastWorkStateServer\test\wx_withdarw.py", line 44, in <module>
wx_withdr()
File "G:\FastWorkStateServer\test\wx_withdarw.py", line 34, in wx_withdr
partner_trade_no=123456789, # 商户订单号
File "G:\FastWorkStateServer\sdk\wx_withdraw.py", line 393, in enterprise_payment
raw = self.fetch_with_ssl(url, data, api_cert_path, api_key_path)
File "G:\FastWorkStateServer\sdk\wx_withdraw.py", line 95, in fetch_with_ssl
cert=(api_client_cert_path, api_client_key_path),
File "C:\Users\ASUS\kuaigong3.6.5\lib\site-packages\requests\api.py", line 112, in post
return request('post', url, data=data, json=json, **kwargs)
File "C:\Users\ASUS\kuaigong3.6.5\lib\site-packages\requests\api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\ASUS\kuaigong3.6.5\lib\site-packages\requests\sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\ASUS\kuaigong3.6.5\lib\site-packages\requests\sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "C:\Users\ASUS\kuaigong3.6.5\lib\site-packages\requests\adapters.py", line 440, in send
timeout=timeout
File "C:\Users\ASUS\kuaigong3.6.5\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen
chunked=chunked)
File "C:\Users\ASUS\kuaigong3.6.5\lib\site-packages\urllib3\connectionpool.py", line 357, in _make_request
conn.request(method, url, **httplib_request_kw)
File "D:\python3.6.5\lib\http\client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "D:\python3.6.5\lib\http\client.py", line 1284, in _send_request
body = _encode(body, 'body')
File "D:\python3.6.5\lib\http\client.py", line 161, in _encode
(name.title(), data[err.start:err.end], name)) from None
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 100-103: Body ('汉字报错') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8. Process finished with exit code 1

主要原因是 请求body里面有 汉字,没有进行untf-8编码导致,解决方法,对data进行 encode()编码 即可

req = requests.post(url, data=data.encode(),cert=(api_client_cert_path, api_client_key_path),)

requests模块报错:Use body.encode('utf-8') if you want to send it encoded in UTF-8.的更多相关文章

  1. ansible执行shell模块和command模块报错| FAILED | rc=127 >> /bin/sh: lsof: command not found和| rc=2 >> [Errno 2] No such file or directory

    命令: ansible -i hosts_20 st  -m shell -a 'service zabbix_agentd star'  -K --become ansible -i hosts_2 ...

  2. pycharm安装 suds模块报错:AttributeError: module 'pip' has no attribute 'main'

    需求:安装suds模块 遇到的问题: 一.报错信息:[file][Default Settint]---Project Interpreter 点击 搜索suds安装模块报错 解决:依据上图提示找到C ...

  3. python pip安装模块报错 "Can't connect to HTTPS URL because the SSL module is not available."

    在升级python版本为3.6之后,pip安装模块报错. 报错信息如图: 原因是系统自带的openssl版本与python3的版本不匹配,所以这里只要升级openssl版本就可以解决问题. yum - ...

  4. python 安装模块报错 response.py", line 302, in _error_catcher

    python 安装模块报错 Exception:Traceback (most recent call last): File "/usr/share/python-wheels/urlli ...

  5. 全网最详细的用pip安装****模块报错:Could not find a version that satisfies the requirement ****(from version:) No matching distribution found for ****的解决办法(图文详解)

    不多说,直接上干货! 问题详情 这个问题,很普遍.如我这里想实现,Windows下Anaconda2 / Anaconda3里正确下载安装用来向微信好友发送消息的itchat库. 见,我撰写的 全网最 ...

  6. 执行Python程序时模块报错

    1. 在执行python程序时遇到 'ModuleNotFoundError: No module named 'xxxxx'' : 例如: 图片中以导入第三方的 'requests' 模块为例,此报 ...

  7. (22)odoo 安装旧模块报错处理

    一些老版本的模块没有得到升级,所以经常碰到模块无法安装的问题. No module name osv 将模块的 from osv import osv,fields 改为 from openerp.o ...

  8. 一招解决OpenERP8.0安装旧版模块报错

    有喜欢尝鲜的网友开始玩8.0了,可是版本还没发布,社区的很多特别好的模块还没有升级到8,所以经常碰到模块无法安装的问题. No module name osv 网友提出将模块的 from osv im ...

  9. 【.NET调用Python脚本】C#调用python requests类库报错 'module' object has no attribute '_getframe' - IronPython 2.7

    最近在开发微信公众号,有一个自定义消息回复的需求 比如用户:麻烦帮我查询一下北京的天气? 系统回复:北京天气,晴,-℃... 这时候需要根据关键字[北京][天气],分词匹配需要执行的操作,然后去调用天 ...

随机推荐

  1. C语言struct小知识

    1.C语言里的struct是不能包含成员函数的,只能有数据成员2.C语言struct定义变量只能用一下两种方式:struct { ... } x, y, z;struct point pt;直接poi ...

  2. centos安装netcat

    Linux安装swoole后,测试UDP服务需要用到netcat,然而百度了很多安装方法,并没有一个好用的.几经尝试,终于安装成功,现在就分享给大家,以供参考. 配置环境:centos6.3 1.下载 ...

  3. composer 安装yii2 The package is not available in a stable-enough version解决办法

    错误 Potential causes: - A typo in the package name - The package is not available in a stable-enough ...

  4. JS IE 打开本地exe程序

    例: try{ //新建一个ActiveXObject对象 var exe = new ActiveXObject("wscript.shell"); var exePath = ...

  5. zookkeper原理学习

    zookkeper原理学习  https://segmentfault.com/a/1190000014479433   https://www.cnblogs.com/felixzh/p/58692 ...

  6. springboot整合shiro-登录认证和权限管理

    https://blog.csdn.net/ityouknow/article/details/73836159

  7. Java中sleep方法和wait的详细区别

    1.两者的区别 对于sleep()方法,我们首先要知道该方法是属于Thread类中的.而wait()方法,则是属于Object类中的. 这两个方法来自不同的类分别是Thread和Object 最主要是 ...

  8. 关于socket阻塞与非阻塞情况下的recv、send、read、write返回值---部分内容可能不确切,待讨论

    1.阻塞模式与非阻塞模式下recv的返回值各代表什么意思?有没有区别?(就我目前了解阻塞与非阻塞recv返回值没有区分,都是 <0:出错,=0:连接关闭,>0接收到数据大小,特别:返回值  ...

  9. bzoj 4811: [Ynoi2017]由乃的OJ

    树链剖分,用zkw线段树维护每条链两个方向上对每一位的变换情况,由于位数较少,可以用两个unsigned long long表示 #include<cstdio> typedef unsi ...

  10. 【转】XP_cmdshell存储过程

    原文地址:http://www.cnblogs.com/love_study/archive/2010/03/02/1676583.html 一 .简介 xp_cmdshell 扩展存储过程将命令字符 ...