在做 企业向微信用户个人付款  功能时,调用第三方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. js检测字符串的字节数

    在js中字符串可以存放数字,字母或者汉字,但是又一个问题就是,数字和字母都是占一个字节,而一个汉字占2个字节.如果在一个字符串中既有字母又有汉字怎么判断字节数呢 第一种简单粗暴 var str = ' ...

  2. gaea-editor 项目使用

    项目地址:https://github.com/ascoders/gaea-editor 打开编辑器界面:运行npm run docs 下载gaea-editor项目,进行调试,注意点: gaea-e ...

  3. 在CentOS6.8系统上安装MySQL5.7(转)

    mysql-57">如何在CentOS 6.8系统上安装MySQL 5.7? 一.检查系统上是否已经安装MySQL 命令: ? 1 2 3 4 5 [root@localhost ~] ...

  4. JMeter 插件 Json Path 解析 HTTP 响应 JSON 数据(转)

    JMeter 是一个不错的负载和性能测试工具,我们也用来做 HTTP API 接口测试.我们的 API 返回结果为 JSON 数据格式.JSON 简介,JSON 教程. JSON 已经成为数据交换格式 ...

  5. JavaScript 继承总结

    http://blog.csdn.net/yincheng01/article/details/6841953 Metro C++ http://www.cnblogs.com/michaelxu/a ...

  6. PHP 中 call_user_func 函数 和 call_user_func_array 函数的区别

    PHP 中 call_user_func() 函数 和 call_user_func_array() 函数都是回调函数,在写接口的时候经常会用到,但是他们有什么区别呢? 它们的第一个参数都是被调用的回 ...

  7. MobaXterm的一些介绍(Top 5 SSH Clients for Windows (Alternatives of PuTTY))

    Top 5 SSH Clients for Windows (Alternatives of PuTTY) http://tecadmin.net/top-5-ssh-clients-for-wind ...

  8. DLL对象类型转换

    //以下代码是错误的!!! //这一节主要告诉大家,以这种方式进行开发dll是不对的以及错误原因,正确的方式是什么! //DLL内创建对象,并把对象返回 function GetDataSet(str ...

  9. Oracle 字符集更改

    sqlplus sys/player as sysdba SQL*Plus: Release 11.2.0.1.0 Production shutdown immediate; startup mou ...

  10. js 处理Json 时间带T 时间格式

    对于后台传过来的json数据是带T时间格式的坑处理的一些做法总结 new Date(data[j].addtime).toISOString().replace(/T/g, ' ').replace( ...