TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type s
Python3:
在使用urllib对参数进行URL编码后,调用
formdata = {
"page_limit": "20",
"page_start": "40"
}
data = parse.urlencode(formdata)
request.Request(url, data=data, headers=headers)
时,出现错误:TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.
意思是,POST发送的数据必须是字节类型,不能为str类型。
解决方法:
修改url编码为data = parse.urlencode(formdata).encode(“UTF8”)即可
还没有评论,来说两句吧...