TIMEX
TIMEX

Reputation: 271764

How come I'm getting this Python error in my code?

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

Upvotes: 0

Views: 1002

Answers (1)

Jarret Hardie
Jarret Hardie

Reputation: 97922

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

Upvotes: 8

Related Questions