我正在编写 python 程序以编程方式登录网站。现在我在处理 cookie 时遇到了问题。以下是我的代码:
import mechanize
cj = mechanize.CookieJar()
browser = mechanize.Browser()
browser.set_cookiejar(cj)
opener = mechanize.build_opener(*browser.handlers)
它给了我这样的错误:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site- packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/home/test/testEnv/apps/arachni/views.py", line 983, in handle_request
content = opener.open(req, data).read()
File "build/bdist.linux-i686/egg/mechanize/_opener.py", line 188, in open
req = meth(req)
File "build/bdist.linux-i686/egg/mechanize/_http.py", line 316, in http_request
self.rfp.read()
File "build/bdist.linux-i686/egg/mechanize/_http.py", line 242, in read
f = self._opener.open(req)
File "build/bdist.linux-i686/egg/mechanize/_opener.py", line 204, in open
response = meth(req, response)
File "build/bdist.linux-i686/egg/mechanize/_urllib2_fork.py", line 457, in http_response
'http', request, response, code, msg, hdrs)
File "build/bdist.linux-i686/egg/mechanize/_opener.py", line 221, in error
result = apply(self._call_chain, args)
File "build/bdist.linux-i686/egg/mechanize/_urllib2_fork.py", line 332, in _call_chain
result = func(*args)
File "build/bdist.linux-i686/egg/mechanize/_urllib2_fork.py", line 571, in http_error_302
return self.parent.open(new)
File "build/bdist.linux-i686/egg/mechanize/_opener.py", line 188, in open
req = meth(req)
File "build/bdist.linux-i686/egg/mechanize/_mechanize.py", line 71, in http_request
request = self.parent._add_referer_header(
AttributeError: OpenerDirector instance has no attribute '_add_referer_header'
好像我没有正确处理“推荐人”。任何想法?