在做 企业向微信用户个人付款  功能时,调用第三方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. Springboot技术点汇总

    1. Springboot+MyBatis+druid 在启动类上面,添加注释@Configuration以及@ImportResource(location={"classpath:con ...

  2. MatConvNet中关于vl_simplenn_display的一些分析

    一.关于各层data size的分析 layer1:  floor((224-7)/2)+1=109 这里7是filter大小,2是stride layer4: floor((109+0+1-3)/2 ...

  3. 【转】Lambda表达式详解

    前言 1.天真热,程序员活着不易,星期天,也要顶着火辣辣的太阳,总结这些东西. 2.夸夸lambda吧:简化了匿名委托的使用,让你让代码更加简洁,优雅.据说它是微软自c#1.0后新增的最重要的功能之一 ...

  4. 运行Spark提供的计算圆周率的示例程序

    1.启动Spark服务 因为spark是依赖于hadoop提供的分布式文件系统的,所以在启动spark之前,先确保hadoop在正常运行. 在hadoop正常运行的情况下,在master(也就是had ...

  5. java jvm设置http代理参数

    -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=1080

  6. centos7 svn服务器的搭建

    centos7下svn的安装与配置   1.环境 centos7 2.安装svnyum -y install subversion 3.配置 建立版本库目录mkdir /www/svndata svn ...

  7. Swoole来实现实时异步任务队列

    假如要发100封邮件,for循环100遍,用户直接揭竿而起,什么破网站!但实际上,我们很可能有超过1万的邮件.怎么处理这个延迟的问题?答案就是用异步.把“发邮件”这个操作封装,然后后台异步地执行1万遍 ...

  8. Centos 7 systemctl和防火墙firewalld命令

    今天自己在Hyper-v下搭建三台Linux服务器集群,用于学习ELKstack(即大数据日志解决技术栈Elasticsearch,Logstash,Kibana的简称),下载的Linux版本为cen ...

  9. django 初始化 介绍 生命周期

    安装好django,配置模板,静态文件 # 创建Django工程 django-admin startproject [工程名称] mysite - mysite # 对整个程序进行配置 - init ...

  10. java中经常使用的Swing组件总结

    1.按钮(Jbutton) Swing中的按钮是Jbutton,它是javax.swing.AbstracButton类的子类,swing中的按钮可以显示图像,并且可以将按钮设置为窗口的默认图标,而且 ...