问题:
python3.7:报错
POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.
原因:
# 组装GET方法的请求
request = urllib2.Request(url, data, headers)
其中的data需要转为utf-8
解决方案:
# 组装GET方法的请求
#将代码request = urllib2.Request(url, data, headers) 更改为
request = urllib.request.Request(url, data=urllib.parse.urlencode(data).encode(encoding=’UTF8′), headers=headers)
- 本文固定链接: http://jingyan.idoubi.net/820.html
- 转载请注明: 游戏创作者大陆 于 逗分享开发经验 发表