requests模块报错:Use body.encode('utf-8') if you want to send it encoded in UTF-8.
在做 企业向微信用户个人付款 功能时,调用第三方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.的更多相关文章
- 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 ...
- pycharm安装 suds模块报错:AttributeError: module 'pip' has no attribute 'main'
需求:安装suds模块 遇到的问题: 一.报错信息:[file][Default Settint]---Project Interpreter 点击 搜索suds安装模块报错 解决:依据上图提示找到C ...
- python pip安装模块报错 "Can't connect to HTTPS URL because the SSL module is not available."
在升级python版本为3.6之后,pip安装模块报错. 报错信息如图: 原因是系统自带的openssl版本与python3的版本不匹配,所以这里只要升级openssl版本就可以解决问题. yum - ...
- python 安装模块报错 response.py", line 302, in _error_catcher
python 安装模块报错 Exception:Traceback (most recent call last): File "/usr/share/python-wheels/urlli ...
- 全网最详细的用pip安装****模块报错:Could not find a version that satisfies the requirement ****(from version:) No matching distribution found for ****的解决办法(图文详解)
不多说,直接上干货! 问题详情 这个问题,很普遍.如我这里想实现,Windows下Anaconda2 / Anaconda3里正确下载安装用来向微信好友发送消息的itchat库. 见,我撰写的 全网最 ...
- 执行Python程序时模块报错
1. 在执行python程序时遇到 'ModuleNotFoundError: No module named 'xxxxx'' : 例如: 图片中以导入第三方的 'requests' 模块为例,此报 ...
- (22)odoo 安装旧模块报错处理
一些老版本的模块没有得到升级,所以经常碰到模块无法安装的问题. No module name osv 将模块的 from osv import osv,fields 改为 from openerp.o ...
- 一招解决OpenERP8.0安装旧版模块报错
有喜欢尝鲜的网友开始玩8.0了,可是版本还没发布,社区的很多特别好的模块还没有升级到8,所以经常碰到模块无法安装的问题. No module name osv 网友提出将模块的 from osv im ...
- 【.NET调用Python脚本】C#调用python requests类库报错 'module' object has no attribute '_getframe' - IronPython 2.7
最近在开发微信公众号,有一个自定义消息回复的需求 比如用户:麻烦帮我查询一下北京的天气? 系统回复:北京天气,晴,-℃... 这时候需要根据关键字[北京][天气],分词匹配需要执行的操作,然后去调用天 ...
随机推荐
- React V16.x 生命周期调整
旧声明周期: table th:nth-of-type(5) { width: 400px; } 生命周期 属于阶段 调用次数 是否可以setState 作用 getDefaultProps 创建阶段 ...
- parcel (另一个打包工具)知识点
ParcelJS 本身是 0 配置的,但 HTML.JS 和 CSS 分别是通过 posthtml.babel 和 postcss 处理的,所以我们得分别配 .posthtmlrc..babelrc ...
- elasticsearch 基础 语法总结
1. es 使用 restful 风格的 api 备注: es 的 api 格式 基本是这个样 请求方式 /索引名/文档名/id?参数 ,但是 还有 很多不是这样的 请求,比如 ...
- c/c++ int数组初始化/重置为0
1.int数组其实初始化的时候默认就是全部为0 int a[1000];int a[1000] = {0}; 以上2种写法其实都可以 注意:int a[1000] = {0};这种方法如果想把整形数组 ...
- bzoj 4184 shallot——线段树分治+线性基
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4184 本来想了可持久化trie,不过空间是 nlogn (出一个节点的时候把 tot 复原就 ...
- VS2015和SVN合作
SVN就是版本控制管理工具. 插件这里,还是遇到了一些问题,我知道有插件了,但是忽略了开始的版本问题,按时插件安装过程中没有出现意外,故以为“插件安装成功”,岂不知此“成功”非彼“成功”.由于我用的是 ...
- SqlServer :利用快捷键快速查看 字段说明查询及表结构 (小技巧)
1.自定义4个常用的存储过程: sp_select :select * from sp_helpremark :查表的列,列的类型,备注(这里只查询有备注的列) sp_columns1 : 查表所有的 ...
- FPGA中关于SPI的使用
FPGA中关于SPI的使用 信息来源 SPI Flash的编程 最新的SPI不止有4根信号线,可以增加到支持4bit的数据宽度 SPI Flash Basics 能够扩展成4bit数据的是MOSI信号
- Vivado HLS初识---阅读《vivado design suite tutorial-high-level synthesis》(4)
Vivado HLS初识---阅读<vivado design suite tutorial-high-level synthesis>(4) 1.老样子,首先运行tcl脚本建工程: Vi ...
- Java事件监听器的四种实现方式
自身类作为事件监听器 外部类作为事件监听器 匿名内部类作为事件监听器 内部类作为事件监听器 自身类作为事件监听器: import javax.swing.*; import java.awt.*; i ...