我有這樣的代碼:如何定義'HTTPCookieProcessor'全局名稱?
class API(object):
def __init__(self):
self.baseuri = "http://api.xxx.xxx"
self.cj = cookielib.CookieJar()
self.cp = urllib2.HTTPCookieProcessor(self.cj)
self.opener = urllib2.build_opener(self.cp)
的錯誤是:NameError: global name 'HTTPCookieProcessor' is not defined
怎麼來的? P.S:
>>> a = api.API()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\lib\xxxxx\api.py", line 9, in __init__
self.cp = urllib2.HTTPCookieProcessor(self.cj)
NameError: global name 'HTTPCookieProcessor' is not defined
發佈的代碼不會給你那個錯誤。你能糾正發佈的代碼幷包含完整的追溯? – AdamKG 2012-03-01 17:40:36