python - 使用 mechanize 和 pythonanywhere 获取 "error Tunnel connection failed: 403 Forbidden"

标签 python web-applications flask mechanize pythonanywhere

我使用 python、mechanize 和 flask 编写了一个小型网络应用程序。当我在本地运行它时,它工作得很好。

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 错误,我该如何解决?

最佳答案

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

关于python - 使用 mechanize 和 pythonanywhere 获取 "error Tunnel connection failed: 403 Forbidden",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20063726/

相关文章:

python - Django 和 Pylons 的中间件

python - 不带shell调用模块

java - Spring-MVC web.xml 文件不使用 ContextLoaderListener

python - Windows Server 2012 上的 Flask、wfastcgi 和 IIS

flask - 为互联网打开端口 5000 不适用于谷歌云计算引擎实例

python - 错误的 ctypes 分配

mysql - app.js 中的代码停止加载 CSS 资源

Java:如何发布此 XML 请求?

python - Flask 在其 URL 路由中是否支持正则表达式?

c++ - Boost.Python dll 在编译时被跳过