欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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"))
相关标签: python