python3.x执行post请求时报错“POST data should be bytes or an iterable of bytes...”的解决方法...

使用python3.5.1执行post请求时,一直报错"POST data should be bytes or an iterable of bytes. It cannot be of type str.",仔细对照教程后也未发现编写方法没有问题。

python3.x执行post请求时报错“POST data should be bytes or an iterable of bytes...”的解决方法..._第1张图片

最后通过交流发现需要加在urlencode语句后加encode(encoding='UTF8')
eg:

params = urllib.parse.urlencode({'userid':'381fccbd776c4deb'}).encode(encoding='UTF8')

原文:https://blog.csdn.net/dushu990/article/details/51767189

 

转载于:https://www.cnblogs.com/anovana/p/10608539.html

你可能感兴趣的:(python3.x执行post请求时报错“POST data should be bytes or an iterable of bytes...”的解决方法...)