import urllib, urllib2
def URLRequest(url, params, method="GET"):
if method == "POST":
return urllib2.Request(url, data=urllib.encode(params)) <<<< 31
else:
return urllib2.Request(url + "?" + urllib.encode(params))
'module' object has no attribute 'encode', line 31
asked Dec 18, 2010 at 23:57
TIMEX
275k369 gold badges804 silver badges1.1k bronze badges
1 Answer 1
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
answered Dec 19, 2010 at 0:04
Jarret Hardie
98.4k10 gold badges135 silver badges127 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
BoltClock
Here you go, 10 rep from me :D
lang-py
urlencodenotencode, so you would callurllib.urlencode(params)urllibhas no attributeencode, that means that there is noencodefunction inurllib!