Search code examples
pythonanywherepytube

forbidden error using pytube on pythonanywhere


I have a similar issue to that which is highlited at https://www.pythonanywhere.com/forums/topic/2688/

the only difference is that I am using flask, and the module I am using is pytube. I trust that you shall help, the error message displayed is:

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>

Solution

  • Youtube doesn't allow downloading videos through their API, so all of the scripts that download youtube videos scrape the www site, and we don't allow scraping from free accounts.

    more info here: http://help.pythonanywhere.com/pages/403ForbiddenError