TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type s
2017-01-08 13:49
2151 查看
直接上代码
看了好久没看出错误,最后无意间在网上发现答案,分享给大家,
大家对照一下找不同就解决了 哈哈。
import urllib.request import urllib.parse def 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)
大家对照一下找不同就解决了 哈哈。
相关文章推荐
- python3 爬虫TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be
- 解决Python3.6,发送POST请求错误提示:POST data should be bytes, an iterable of bytes, or a file object. It canno
- python3爬虫问题 POST data should be bytes or an iterable of bytes
- 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...”的解决方法
- File ID 1 of database ID 6 cannot be shrunk as it is either being shrunk by another process or is empty 的解决方案
- Could not load file or assembly 'System.Data.SQLite' or one of its dependencies. An attempt was made
- spring同时使用aop和spel表达式出错:Property or field 'instrument' cannot be found on object of type 'com.sun.pr
- spring同时使用aop和spel表达式出错:Property or field 'instrument' cannot be found on object of type 'com.sun.pr
- Property or field 'siteUrl' cannot be found on object of type 'xx' - maybe not public?
- 错误:Property or field 'default' cannot be found on object of type 'com.netflix.appinfo.InstanceInfo'
- The type java.lang.Object cannot be resolved.It is indirectly referenced from required .class file
- 错误处理:"Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was
- Property or field 'str' cannot be found on object of type 'com.yubai.EL.DemoService' - maybe not pub
- The type java.lang.Object cannot be resolved.It is indirectly referenced from required .class file
- TypeError: super(type, obj): obj must be an instance or subtype of type
- 【spring-security】 Property or field 'ROLE_USER' cannot be found on object of type 'org.springframewo
- WCF:Maximum number of items that can be serialized or deserialized in an object graph is '65536'.
- 1、The type java.lang.Object cannot be resolved.It is indirec....