TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.
爬虫遇坑:发送POST请求,转码data错误提示
爬虫时,转码data时,出现下面错误信息:
TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.
报错截图:
报错原因:
请求数据时,没有编码成UTF-8
修改代码:
修改前:post_data = urllib.parse.urlencode(post_data)
修改后:post_data = urllib.parse.urlencode(post_data).encode(‘utf-8’)