mechanize._response.httperror_seek_wrapper:HTTP错误403:好的

时间:2015-12-31 06:34:13

标签: python login mechanize http-status-code-403 login-script

我多次尝试的内容:
1.改变标题来欺骗它,不起作用 2.尝试了nr=0nr=1nr=2也不起作用 3.确认用户名和密码是否正确
4.同样的脚本适用于其他类似网站。

所有尝试都会返回错误:

  

mechanise._response.httperror_seek_wrapper:HTTP错误403:确定

有关stackoverflow的其他现有问题会出现403: Forbidden403:Forbidden by robots.txt的情况,但实际上没有“OK”这个独特的情况。

# !/usr/bin/python

import mechanize

br = mechanize.Browser()
br.set_debug_http(True)
br.set_debug_redirects(True)
br.set_debug_responses(True)

br.set_handle_equiv(False)
br.set_handle_gzip(False)
br.set_handle_redirect(True)
br.set_handle_referer(False)
br.set_handle_robots(False)
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
br.addheaders = [('User-agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'), ('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'),('Accept-Encoding', 'none'),('Accept-Language', 'en-US,en;q=0.8'),('Connection', 'keep-alive')]

def login():

    br._factory.is_html = True
    br.open('https://circleup.com/login/')
    #br.form.set_all_readonly(False)
    br.select_form(nr=2)
    br['username'] = '***********'
    br['password'] = '***********'
    br.method = "post"
    br.submit()


login()

结果:

    br.submit()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mechanize/_mechanize.py", line 541, in submit
    return self.open(self.click(*args, **kwds))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mechanize/_mechanize.py", line 203, in open
    return self._mech_open(url, data, timeout=timeout)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mechanize/_mechanize.py", line 255, in _mech_open
    raise response
mechanize._response.httperror_seek_wrapper: HTTP Error 403: OK

1 个答案:

答案 0 :(得分:0)

您有 HTTP错误403 ,表示身份验证错误。 虽然它不是 407代理身份验证错误,但它可能意味着机械化的代理身份验证问题。

您是否在代理背后工作?如果是这样,你应该考虑将〜/ .bash_profile或〜/ .profile设置为;

export {http_proxy,https_proxy,ftp_proxy}=http://<username>:<pass>@<proxy_address>:<port>

如果您已设置代理,如果您通过 crontab 运行脚本,也可能会出现此错误。如果是这样,您应该在crontab中将代理设置设置为;

http_proxy=http://<username>:<pass>@<proxy_address>:<port>
https_proxy=https://<username>:<pass>@<proxy_address>:<port>

我希望这有效。