1

I am using pafy in a Flask app. It is working fine on my local machine. But when I am trying to deploy and run on PythonAnywhere, it is throwing an error. Upon execution, it is showing the following ewrror:

youtube_dl.utils.ExtractorError: Unable to download API page: <urlopen error Tunnel connection failed: 403 Forbidden> (caused by URLError(OSError('Tunnel connection failed: 403 Forbidden'))) NO MATCH During handling of the above exception, another exception occurred: NO MATCH Traceback (most recent call last): File "/home/Philomath/.local/lib/python3.8/site-packages/pafy/backend_youtube_dl.py", line 40, in _fetch_basic self._ydl_info = ydl.extract_info(self.videoid, download=False) File "/home/Philomath/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 808, in extract_info return self.__extract_info(url, ie, download, extra_info, process) File "/home/Philomath/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 824, in wrapper self.report_error(compat_str(e), e.format_traceback()) File "/home/Philomath/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 628, in report_error self.trouble(error_message, tb) File "/home/Philomath/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 598, in trouble raise DownloadError(message, exc_info) youtube_dl.utils.DownloadError: ERROR: Unable to download API page: <urlopen error Tunnel connection failed: 403 Forbidden> (caused by URLError(OSError('Tunnel connection failed: 403 Forbidden')))

I have also removed the lines for dislike count in backend_yoututbe_dl in PythonAnywhere (from bash). Still, no use.

davidism
  • 121,510
  • 29
  • 395
  • 339
Phil
  • 21
  • 3
  • Are you sure it's working fine on your local machine? – George Mar 04 '23 at 11:53
  • Yes. I have tested several times on my local machine. It is working perfectly. – Phil Mar 04 '23 at 11:54
  • Make sure that you are using full URL of the youtube videos – Samudra Ganguly Mar 04 '23 at 11:57
  • I don't think there will be any difference for that – George Mar 04 '23 at 11:57
  • The error message suggests that there is a problem with accessing the YouTube API page such as network connectivity issues or restrictions on the server you are running the app on. – Sullivan Mar 04 '23 at 11:59
  • According to the question, the server is PythonAnywhere – George Mar 04 '23 at 12:01
  • Check if there are any network restrictions or firewalls that might be blocking the connection to the YouTube API, Update `youtube_dl` to the last version or try using a different library for downloading videos from YouTube, such as `pytube`. – Sullivan Mar 04 '23 at 12:01
  • @George yes I am using PythonAnywhere. – Phil Mar 04 '23 at 12:02
  • @Sullivan I need to stream the video. If I am not mistaken, Pytube downloads the video in a file. – Phil Mar 04 '23 at 12:03
  • if with `pytube` you are able to download from youtube then `youtube_dl` has a problem – Sullivan Mar 04 '23 at 12:03
  • you can use `pytube` for stream the video – Sullivan Mar 04 '23 at 12:04
  • @Sullivan using VLC? – Phil Mar 04 '23 at 12:05
  • @Phil Yes you can using VLC for stream the video – Sullivan Mar 04 '23 at 12:06
  • @Sullivan I need to stream the video inside **video** tag in webpage. I used flask to get the URL and pass the stream as parameter inside the **video** tag. Can I achieve the same using Pytube? – Phil Mar 04 '23 at 12:07
  • @Phil you can get stream link with this code`from pytube import YouTube yt = YouTube(f'https://www.youtube.com/watch?v={video_id}') stream_url = yt.streams.first().url` – Sullivan Mar 04 '23 at 12:12
  • sorry for the bad format – Sullivan Mar 04 '23 at 12:12
  • I tried using Pytube. It is working fine in local machine but causing a similar issue in Flask. OSError: Tunnel connection failed: 403 Forbidden **NO MATCH** During handling of the above exception, another exception occurred: **NO MATCH** Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2077, in wsgi_app response = self.full_dispatch_request() File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1525, in full_dispatch_request – Phil Mar 04 '23 at 12:29

1 Answers1

2

That will not work on PythonAnywhere. Any youtube video downloads use unofficial methods and so PythonAnywhere will not add youtube to the allowlist for free accounts.

Glenn
  • 7,262
  • 1
  • 17
  • 23