在 pythonanywhere 上使用 pytube 时出现禁止错误

forbidden error using pytube on pythonanywhere

我有一个与 https://www.pythonanywhere.com/forums/topic/2688/

中突出显示的问题类似的问题

唯一不同的是我用的是flask,而我用的模块是pytube。我相信你会帮助,显示的错误信息是:

Traceback (most recent call last):
File "/home/*username*/.virtualenvs/*project*/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request() 
File "/home/*username*/.virtualenvs/*project*/local/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e) 
File "/home/*username*/.virtualenvs/*project*/local/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb) 
File "/home/*username*/.virtualenvs/*project*/local/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request() 
File "/home/*username*/.virtualenvs/*project*/local/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functionsrule.endpoint 
File "/home/*username*/<project>/app.py", line 49, in upload
    ytube = YouTube(url) 
File "/home/*username*/.virtualenvs/*project*/local/lib/python2.7/site-packages/pytube/api.py", line 66, in init
    self.from_url(url) 
File "/home/*username*/.virtualenvs/*project*/local/lib/python2.7/site-packages/pytube/api.py", line 158, in from_url
    video_data = self.get_video_data() 
File "/home/*username*/.virtualenvs/*project*/local/lib/python2.7/site-packages/pytube/api.py", line 254, in get_video_data
    response = urlopen(self.url) 
File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout) 
File "/usr/lib/python2.7/urllib2.py", line 404, in open
    response = self._open(req, data) 
File "/usr/lib/python2.7/urllib2.py", line 422, in _open
    '_open', req) 
File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
    result = func(*args) 
File "/usr/lib/python2.7/urllib2.py", line 1222, in https_open
    return self.do_open(httplib.HTTPSConnection, req) 
File "/usr/lib/python2.7/urllib2.py", line 1184, in do_open
    raise URLError(err) URLError: <urlopen error Tunnel connection failed: 403 Forbidden>

Youtube 不允许通过他们的 API 下载视频,因此所有下载 youtube 视频的脚本都会抓取 www 站点,我们不允许从免费帐户抓取。

更多信息在这里:http://help.pythonanywhere.com/pages/403ForbiddenError