POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.
程序员文章站
2022-05-04 11:45:32
...
今天写Python爬虫POST请求有道翻译使出现了以下问题:
开始百思不得其解,想了好久,发现还是转码的时候没有转成bytes类型
主要修改两个地方
1.通过urlencode转码时,在最后面加 encode(‘utf-8’)
data=urllib.parse.urlencode(formdata).encode("utf-8")#转码
print(urllib.request.urlopen(request).read().decode("utf-8"))
修改这两个地方之后就可以了
上一篇: 爬虫有道词典
下一篇: Python 爬虫小练习--爬取有道词典
推荐阅读
-
TypeError: POST data should be bytes, an iterable of bytes, or a file object.制作有道翻译小翻译软件的问题解决方法
-
TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type s
-
TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type s
-
POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.
-
TypeError:POST data should be bytes, an iterable of bytes, or a file object. It cannot be of str