import urllib, urllib2
def URLRequest(url, params, method="GET"):
if method == "POST":
return urllib2.Request(url, data=urllib.encode(params)) <<<< 31
else:
r开发者_开发百科eturn urllib2.Request(url + "?" + urllib.encode(params))
'module' object has no attribute 'encode', line 31
The error message is correct: the urllib
module does not have an encode()
function. The function name is urlencode()
, so you would call:
urllib.urlencode(params)
Python docs for the function: http://docs.python.org/library/urllib.html#urllib.urlencode
精彩评论