Python3.x:報錯POST data should be bytes, an iterable of bytes
問題:
python3.x:報錯
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)