获得;错误隧道连接失败:403禁止“;使用机械化和pythonanywhere

获得;错误隧道连接失败:403禁止“;使用机械化和pythonanywhere,python,web-applications,flask,mechanize,pythonanywhere,Python,Web Applications,Flask,Mechanize,Pythonanywhere,我使用python、mechanize和flask编写了一个小型Web应用程序。当我在本地运行它时,它工作得非常好 在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.ful

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

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>
回溯(最近一次呼叫最后一次):
wsgi_应用程序中的文件“/usr/local/lib/python2.7/dist packages/flask/app.py”,第1687行
response=self.full\u dispatch\u request()
文件“/usr/local/lib/python2.7/dist packages/flask/app.py”,第1360行,完整发送请求
rv=自身处理用户异常(e)
文件“/usr/local/lib/python2.7/dist packages/flask/app.py”,第1358行,完整发送请求
rv=自我分派请求()
文件“/usr/local/lib/python2.7/dist packages/flask/app.py”,第1344行,在调度请求中
返回self.view_函数[rule.endpoint](**req.view_参数)
文件“/home/Lanaru/mysite/gpaviewer.py”,第34行,在索引中
gpa=get_gpa(request.form['username'],request.form['password'])
****get_gpa中第11行的文件“/home/Lanaru/mysite/gpaviewer.py”
br.打开(r'https://websiteomitted.com/')
文件“/usr/local/lib/python2.7/dist packages/mechanize/_mechanize.py”,第203行,打开
返回self.\u mech\u open(url、数据、超时=超时)
文件“/usr/local/lib/python2.7/dist-packages/mechanize/_-mechanize.py”,第230行,处于打开状态
response=UserAgentBase.open(self、request、data)
文件“/usr/local/lib/python2.7/dist packages/mechanize/_opener.py”,第193行,打开
响应=urlopen(自我、请求、数据)
文件“/usr/local/lib/python2.7/dist-packages/mechanize/_-urlib2_-fork.py”,第344行,打开
"开放",
文件“/usr/local/lib/python2.7/dist packages/mechanize/_urlib2_fork.py”,第332行,在调用链中
结果=func(*args)
文件“/usr/local/lib/python2.7/dist packages/mechanize/_urlib2_fork.py”,第1170行,https_open
返回自动打开(连接工厂,需要)
文件“/usr/local/lib/python2.7/dist packages/mechanize/_urlib2_fork.py”,第1118行,在dou open中
引发URL错误(err)
URL错误:

为什么我会遇到这个urlopen错误以及如何修复它?

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

那就是了。不过,我认为我还没有准备好为他们的服务付费。有免费的pythonany替代品吗?如果你能@Miguel可能的复制品,请看这篇文章