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. ORA-12899: value too large for column

    ORA-12899: value too large for column "SOAU"."SJQY_QTSBSPEC"."PROPERTY_6&qu ...

  2. 【BZOJ2797】[Poi2012]Squarks 暴力乱搞

    [BZOJ2797][Poi2012]Squarks Description 设有n个互不相同的正整数{X1,X2,...Xn},任取两个Xi,Xj(i≠j),能算出Xi+Xj.现在所有取法共n*(n ...

  3. 【BZOJ2095】[Poi2010]Bridges 动态加边网络流

    [BZOJ2095][Poi2010]Bridges Description YYD为了减肥,他来到了瘦海,这是一个巨大的海,海中有n个小岛,小岛之间有m座桥连接,两个小岛之间不会有两座桥,并且从一个 ...

  4. Fragment,仿QQ空间

    转载请注明出处:http://blog.csdn.net/yangyu20121224/article/details/9023451          在今天的这篇文章当中,我依然会以实战加理论结合 ...

  5. spring-boot Web集群

    SpringBoot启动类增加注解 @EnableRedisHttpSession @SpringBootApplication @ImportResource({"classpath:co ...

  6. [iOS微博项目 - 4.6] - 微博配图

    github: https://github.com/hellovoidworld/HVWWeibo A.微博配图 1.需求 显示原创微博.转发微博的缩略图 4张图使用2x2布局,其他使用3x3布局, ...

  7. Spark源码分析 – Dependency

    Dependency 依赖, 用于表示RDD之间的因果关系, 一个dependency表示一个parent rdd, 所以在RDD中使用Seq[Dependency[_]]来表示所有的依赖关系 Dep ...

  8. d3.js:数据可视化利器之 selection:选择集

    选择集/selection 选择集/selection是d3中的核心对象,用来封装一组从当前HTML文档中选中的元素: d3提供了两个方法用来创建selection对象: select(selecto ...

  9. node.js + mongodb 做项目的详解(二)

    这次内容是结合bootstrap把登陆注册做好,还有就是express的中间件等问题. 看这篇博客之前建议先看我上篇写的那篇博客http://www.cnblogs.com/hubwiz/p/4118 ...

  10. 十個必用的 Vim Plugin

    ◎ The NERD Tree 操作 Vim 時,通常都在 Terminal 底下作用,無法像一般的 GUI    應用程式可以以樹狀目錄來瀏覽檔案. The NERD Tree    是一將檔案目錄 ...