0
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
4
  • 2
    The function name is urlencode not encode, so you would call urllib.urlencode(params) Commented Dec 18, 2010 at 23:59
  • @Jarret: That should be an answer ;) Commented Dec 19, 2010 at 0:02
  • 2
    The error message is pretty clear, no? If urllib has no attribute encode, that means that there is no encode function in urllib! Commented Dec 19, 2010 at 0:04
  • @BoltClock... heh heh, you're right, I was just too lazy to look up the link to the function in the API. Duly answered (with link) Commented Dec 19, 2010 at 0:05

1 Answer 1

8

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
Sign up to request clarification or add additional context in comments.

1 Comment

Here you go, 10 rep from me :D

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.