TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type s
程序员文章站
2022-07-15 15:36:19
...
TypeError: POST data should be bytes, an iterable of bytes, or a file
object. It cannot be of type str.
这是因为POST数据需要是字节或文件句柄对象,不能是字符,转换一下(encode)就好了:
data = urllib.parse.urlencode(formData).encode("utf-8")
request = urllib.request.Request(url, data=data, headers=header)
print(urllib.request.urlopen(request).read().decode("utf-8"))
推荐阅读
-
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