Python3.x:报错POST data should be bytes, an iterable of bytes

问题:

python3.x:报错

POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.

原因:

# 组装GET方法的请求
request = urllib2.Request(url, data, headers)

其中的data需要转为utf-8

解决方案:

# 组装GET方法的请求
#将代码request = urllib2.Request(url, data, headers) 更改为
request = urllib.request.Request(url, data=urllib.parse.urlencode(data).encode(encoding='UTF8'), headers=headers)

Python3.x:报错POST data should be bytes, an iterable of bytes的更多相关文章

  1. ELK之kibana的web报错[request] Data too large, data for [<agg [2]>] would be larger than limit of

    http://blog.51cto.com/11819159/1926411 ELK架构:elasticsearch+kibana+filebeat 版本信息: elasticsearch 5.2.1 ...

  2. centos7中python3.6报错ModuleNotFoundError: No module named '_ssl' 或者 Max retries exceeded with url: / (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",))

    如果在运行爬虫时报此错:requests.exceptions.SSLError: HTTPSConnectionPool(host='www.baidu.com', port=443): Max r ...

  3. Python3+selenium 报错处理:“selenium.common.exceptions.NoAlertPresentException: Message: No alert is active”

    一.说明 在使用python3+selenium写自动升级程序的时侯,碰到一个弹出对话框需要点击确认的场景.弹出的对话框如下图所示. 对于弹框各种资料都说通过switch_to.alert属性获取对话 ...

  4. grasshopper | 通过图层引用线条 报错:“ Data conversion failed from Guid to Curve ”的避免方法

    需求:通过 LunchBox - > layer reference 电池 可以快速选中图层所在的线条,但是选择的数据流错误 直接选择会报错--"Data conversion fai ...

  5. C# UTF8的BOM导致XML序列化与反序列化报错:Data at the root level is invalid. Line 1, position 1.

    最近在写一个xml序列化及反序列化实现时碰到个问题,大致类似下面的代码: class Program { static void Main1(string[] args) { var test = n ...

  6. python3 tkinter报错:_tkinter.TclError: cannot use geometry manager pack inside . which already has slaves managed by grid

    报错: _tkinter.TclError: cannot use geometry manager pack inside . which already has slaves managed by ...

  7. CentOS7.5安装Python3.7报错:configure: error: no acceptable C compiler found in $PATH --Python3

    1.问题解析 报错信息中有这样一条:configure: error: no acceptable C compiler found in $PATH即:配置错误,在$path中找不到可接受的C编译器 ...

  8. python3+django报错testserver

    manage.py testserver --addrport 127.0.0.1 报错 查看其它项目 manage.py runserver --addrport 127.0.0.1 正常 查找配置 ...

  9. [已解决]报错:xlrd.compdoc.CompDocError: Workbook: size exceeds expected 17920 bytes; corrupt?

    报错代码如下: filePath='test.xls' data=pd.read_excel(filePath) print(data.head()) 报错内容如下: Traceback (most ...

随机推荐

  1. 【黑金原创教程】【TimeQuest】【第五章】网表质量与外部模型

    声明:本文为黑金动力社区(http://www.heijin.org)原创教程,如需转载请注明出处,谢谢! 黑金动力社区2013年原创教程连载计划: http://www.cnblogs.com/al ...

  2. 离线微博工具Open Live Writer(Windows Live Writer)安装过程及server error 500错误解决

    必备条件: .net framework 3.5框架(大概是要求3.5或以上,不确定,好像没有人遇到和这个相关的问题) 2017年7月27日最新官方版0.6.2英文离线客户端网盘下载(官网的安装包无法 ...

  3. 使用RODBC连接MySQL数据库(R-3.4.3)

    1.安装RODBC包 install.packages("RODBC") 2.配置ODBC 首先查看是否有mysqlODBC5.1Driver  如果没有mysqlODBC5.1D ...

  4. SignalR 循序渐进(五)多个Hub服务器下的消息订阅

    SignalR的通讯方式决定了其高性能,但是即便如此,当消息的并发量上来以后,单节点的Hub服务器依然可能无法承载总的消息吞吐量,那么如何对Hub服务器做水平扩展呢? 从微软官方的文档上看,Signa ...

  5. MongoDB 使用 ObjectId 代替时间

    An ObjectId is a 12-byte unique identifier consisting of: a 4-byte value representing the seconds si ...

  6. Apache Kafka Replication Design – High level

    参考,https://cwiki.apache.org/confluence/display/KAFKA/Kafka+Replication Kafka Replication High-level ...

  7. golang几种post方式

    用golang进行http请求类型多了,总结备忘一下. 1.普通的post\get请求 var r http.Request r.ParseForm() r.Form.Add("uuid&q ...

  8. Python数据分析(一):工具的简单使用

    1.Numpy 安装:pip install numpy [root@kvm work]# cat numpy_test.py #!/usr/bin/env python #coding:utf-8 ...

  9. Websocket - Websocket原理(握手、解密、加密)、基于Python实现简单示例

    一.Websocket原理(握手.解密.加密) WebSocket协议是基于TCP的一种新的协议.WebSocket最初在HTML5规范中被引用为TCP连接,作为基于TCP的套接字API的占位符.它实 ...

  10. python-gitlab 模块

    安装:pip install python-gitlab import gitlab # 登录 gl = gitlab.Gitlab('http://127.0.0.1', private_token ...