TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type s
来源:互联网 发布:宁波最新房价走势知乎 编辑:程序博客网 时间:2024/05/16 08:13
直接上代码
import urllib.requestimport urllib.parsedef request(): #定义 HTTP的头部 headers = {'User-Agent':'Mozilla/5.0','x-my-header':'my value'} req = urllib.request.Request('http://blog.kamidox.com',headers = headers) s = urllib.request.urlopen(req) print(s.read(100)) print(req.headers) s.close() def request_post_debug(): #post data = {'username':'kamidox','password':'xxxxxxx'} headers = {'User-Agent':'Mozilla/5.0'} req = urllib.request.Request('http://www.douban.com',data = urllib.parse.urlencode(data),headers = headers) #创建一个打开器 opener = urllib.request.build_opener(urllib.request.HTTPHandler(debuglevel = 1)) s = opener.open(req) print(s.read(100)) s.close()if __name__=='__main__': request_post_debug()
看了好久没看出错误,最后无意间在网上发现答案,分享给大家,
Request('http://www.douban.com',data = urllib.parse.urlencode(data).encode(encoding='UTF8'),headers = headers)
大家对照一下找不同就解决了 哈哈。
0 0
- TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type s
- 解决Python3.6,发送POST请求错误提示:POST data should be bytes, an iterable of bytes, or a file object. It canno
- Python3.x执行POST请求是出现POST data should be bytes or an iterable of bytes. It cannot be of type str.错误
- python3爬虫问题 POST data should be bytes or an iterable of bytes
- python3爬虫问题 POST data should be bytes or an iterable of bytes
- python3.x执行post请求时报错“POST data should be bytes or an iterable of bytes...”的解决方法
- TypeError: super(type, obj): obj must be an instance or subtype of type
- The type OneInterface cannot be a superinterface of OneInterfaceImpl; a superinterface must be an in
- TypeError: the JSON object must be str, not 'bytes'
- Python之Headers value 1 must be of type str or bytes, not <class 'int'>错误的解决
- Field or property 'ROLE_USER' cannot be found on object of type 'org.springframework.security.web.ac
- 【spring-security】 Property or field 'ROLE_USER' cannot be found on object of type 'org.springframewo
- Property or field 'siteUrl' cannot be found on object of type 'xx'
- Property or field 'str' cannot be found on object of type 'com.yubai.EL.DemoService'
- 错误:Property or field 'default' cannot be found on object of type 'com.netflix.appinfo.InstanceInfo'
- A project with an Output Type of Class Library cannot be started directly
- A project with an Output Type of Class Library cannot be started directly
- A project with an Output Type of Class Library cannot be started directly
- laravel的Eloquent关联关系
- UVa679: dropping balls
- Memcached的简单使用
- Tomcat 安装及其单机多实例部署
- laravel的Eloquent其他笔记
- TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type s
- Android源码设计模式解析与实战
- Caffe-python interface 学习|网络训练、部署、测试
- Share the experience of how to debug dead lock
- 在Android so文件的.init、.init_array上和JNI_OnLoad处下断点
- MongoDB数据库未授权访问漏洞及加固
- Nginx 负载均衡及其 HTTPS 部署
- 面试题之常用–排序算法01
- win10 vs2015 编译 wxSqlite3