So I converted my project to a docker image so it can be run without having local installations of programs except docker. I used the following docker-compose.yml
file:
version: '3'
services:
web:
build: .
command: bash -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
volumes:
- .:/yt-processor
ports:
- "8000:8000"
It has its own SQLite db, hence the migrate command, but the issue that I am facing is that PyTube can't connect to the internet to download the file. The error is specifically in this command:
from pytube import YouTube
...
yt = YouTube(video_url)
I tried using ping google.com
in the image and it returned successful results but somehow this part of the code doesn't want to work. The project works great in my local machine but as soon as I create a docker image and try to execute it there, nothing works. Here's a log of the same command being executed in the docker shell:
# python
Python 3.10.13 (main, Nov 29 2023, 05:20:19) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pytube import YouTube
>>> yt = YouTube("https://www.youtube.com/watch?v=480OGItLZNo")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.10/site-packages/pytube/__main__.py", line 91, in __init__
self.prefetch()
File "/usr/local/lib/python3.10/site-packages/pytube/__main__.py", line 181, in prefetch
self.vid_info_raw = request.get(self.vid_info_url)
File "/usr/local/lib/python3.10/site-packages/pytube/request.py", line 36, in get
return _execute_request(url).read().decode("utf-8")
File "/usr/local/lib/python3.10/site-packages/pytube/request.py", line 24, in _execute_request
return urlopen(request) # nosec
File "/usr/local/lib/python3.10/urllib/request.py", line 216, in urlopen
return opener.open(url, data, timeout)
File "/usr/local/lib/python3.10/urllib/request.py", line 525, in open
response = meth(req, response)
File "/usr/local/lib/python3.10/urllib/request.py", line 634, in http_response
response = self.parent.error(
File "/usr/local/lib/python3.10/urllib/request.py", line 557, in error
result = self._call_chain(*args)
File "/usr/local/lib/python3.10/urllib/request.py", line 496, in _call_chain
result = func(*args)
File "/usr/local/lib/python3.10/urllib/request.py", line 749, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "/usr/local/lib/python3.10/urllib/request.py", line 525, in open
response = meth(req, response)
File "/usr/local/lib/python3.10/urllib/request.py", line 634, in http_response
response = self.parent.error(
File "/usr/local/lib/python3.10/urllib/request.py", line 563, in error
return self._call_chain(*args)
File "/usr/local/lib/python3.10/urllib/request.py", line 496, in _call_chain
result = func(*args)
File "/usr/local/lib/python3.10/urllib/request.py", line 643, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 410: Gone
Can someone point me to the right direction?