使用 mechanize 和 pythonanywhere 获取“错误隧道连接失败:403 Forbidden”

Posted

技术标签:

【中文标题】使用 mechanize 和 pythonanywhere 获取“错误隧道连接失败:403 Forbidden”【英文标题】:Getting "error Tunnel connection failed: 403 Forbidden" with mechanize and pythonanywhere 【发布时间】:2013-12-02 13:03:30 【问题描述】:

我使用 python、mechanize 和 flask 编写了一个小型 webapp。当我在本地运行它时,它可以完美运行。

pythonanywhere.com 上部署时,我收到“内部服务器错误”,并带有以下堆栈跟踪:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1687, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1360, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1358, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1344, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/Lanaru/mysite/gpaviewer.py", line 34, in index
    gpa = get_gpa(request.form['username'], request.form['password'])
**** File "/home/Lanaru/mysite/gpaviewer.py", line 11, in get_gpa
    br.open(r'https://websiteomitted.com/')
  File "/usr/local/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 203, in open
    return self._mech_open(url, data, timeout=timeout)
  File "/usr/local/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 230, in _mech_open
    response = UserAgentBase.open(self, request, data)
  File "/usr/local/lib/python2.7/dist-packages/mechanize/_opener.py", line 193, in open
    response = urlopen(self, req, data)
  File "/usr/local/lib/python2.7/dist-packages/mechanize/_urllib2_fork.py", line 344, in _open
    '_open', req)
  File "/usr/local/lib/python2.7/dist-packages/mechanize/_urllib2_fork.py", line 332, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python2.7/dist-packages/mechanize/_urllib2_fork.py", line 1170, in https_open
    return self.do_open(conn_factory, req)
  File "/usr/local/lib/python2.7/dist-packages/mechanize/_urllib2_fork.py", line 1118, in do_open
    raise URLError(err)
URLError: <urlopen error Tunnel connection failed: 403 Forbidden>

为什么会出现这个 urlopen 错误,我该如何解决?

【问题讨论】:

open url from pythonanywhere的可能重复 【参考方案1】:

如果您在 pythonanywhere.com 上使用免费帐户,请记住,通过 urllib2 访问外部站点仅限于一组 white listed hosts。付费帐户可以访问任何外部网站。

【讨论】:

那就这样吧。不过,我认为我还没有准备好为他们的服务付费。 pythonanywhere有什么免费的替代品吗? 如果可以的话请看看这篇文章@Miguel ***.com/questions/29317916/…

以上是关于使用 mechanize 和 pythonanywhere 获取“错误隧道连接失败:403 Forbidden”的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 Mechanize 处理 JavaScript?

性能测试框架Multi-Mechanize安装与使用

Perl 与 Parallel::ForkManager 和 WWW::Mechanize 一起崩溃

在 python 中使用 mechanize 剥离 html 标签并仅返回文本

在 MacOS Big Sur 上使用 perl WWW:Mechanize

Ruby登录使用mechanize进行spotify