1
2
3
4
5
6
7
|
import urllib
data = urllib.parse.urlencode(params).encode( 'utf-8' )
req = urllib.request.Request(url, data) req.add_header( 'Content-Type' , "application/x-www-form-urlencoded" )
response = urllib.request.urlopen(req) the_page = response. read ().decode( 'utf-8' )
print(the_page) |
如果不做encode,会直接报错:POST data should be bytes or an iterable of bytes. It cannot be of type str.
如果不做decode,看到的都是assic码
本文转自wangfeng7399 51CTO博客,原文链接:http://blog.51cto.com/wangfeng7399/1900613,如需转载请自行联系原作者