开发者

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:
        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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜