Pytube: urllib.error.HTTPError: HTTP Error 410: Gone
Asked Answered
S

9

21

I've been getting this error on several programs for now. I've tried upgrading pytube, reinstalling it, tried some fixes, changed URLs and code, but nothing seems to work.

from pytube import YouTube

#ask for the link from user
link = input("Enter the link of YouTube video you want to download:  ")
yt = YouTube(link)

#Showing details
print("Title: ",yt.title)
print("Number of views: ",yt.views)
print("Length of video: ",yt.length)
print("Rating of video: ",yt.rating)
#Getting the highest resolution possible
ys = yt.streams.get_highest_resolution()

#Starting download
print("Downloading...")
ys.download()
print("Download completed!!")

and this is the error code:

  File "C:\Users\Madjid\PycharmProjects\pythonProject\app2.py", line 6, in <module>
    yt = YouTube(link)
  File "C:\Users\Madjid\PycharmProjects\pythonProject\venv\lib\site-packages\pytube\__main__.py", line 91, in __init__
    self.prefetch()
  File "C:\Users\Madjid\PycharmProjects\pythonProject\venv\lib\site-packages\pytube\__main__.py", line 181, in prefetch
    self.vid_info_raw = request.get(self.vid_info_url)
  File "C:\Users\Madjid\PycharmProjects\pythonProject\venv\lib\site-packages\pytube\request.py", line 36, in get
    return _execute_request(url).read().decode("utf-8")
  File "C:\Users\Madjid\PycharmProjects\pythonProject\venv\lib\site-packages\pytube\request.py", line 24, in _execute_request
    return urlopen(request)  # nosec
  File "E:\Python\lib\urllib\request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "E:\Python\lib\urllib\request.py", line 523, in open
    response = meth(req, response)
  File "E:\Python\lib\urllib\request.py", line 632, in http_response
    response = self.parent.error(
  File "E:\Python\lib\urllib\request.py", line 555, in error
    result = self._call_chain(*args)
  File "E:\Python\lib\urllib\request.py", line 494, in _call_chain
    result = func(*args)
  File "E:\Python\lib\urllib\request.py", line 747, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "E:\Python\lib\urllib\request.py", line 523, in open
    response = meth(req, response)
  File "E:\Python\lib\urllib\request.py", line 632, in http_response
    response = self.parent.error(
  File "E:\Python\lib\urllib\request.py", line 561, in error
    return self._call_chain(*args)
  File "E:\Python\lib\urllib\request.py", line 494, in _call_chain
    result = func(*args)
  File "E:\Python\lib\urllib\request.py", line 641, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 410: Gone
Stodgy answered 6/8, 2021 at 10:46 Comment(1)
This has been asked and answered recently here: How do I download YouTube videos with Python?Martinelli
J
31

Try to upgrade, there is a fix in version 11.0.0:

python -m pip install --upgrade pytube
Jessabell answered 19/8, 2021 at 12:54 Comment(2)
pytube doesn't install/upgrade by pip anymore its supported on brewRacer
I had the same problem and this solution worked for me in May 2023. Many thanks!Westhead
H
7

If you haven't already, install Git on your PC: https://git-scm.com/download/win

Then open the command window as admin and install this patch:

python -m pip install git+https://github.com/Zeecka/pytube@fix_1060
Heliotropism answered 6/8, 2021 at 13:23 Comment(0)
H
6

I build mine from start to bottom, and ran into to same issue here are the code and steps.

Code:

from pytube import YouTube
from sys import argv



link = argv[1]
yt = YouTube(link)



yd = yt.streams.get_highest_resolution()

yd.download(r'C:/Users/adam/OneDrive/Desktop/video')

got error:

urllib.error.HTTPError: HTTP Error 410: Gone

STEPS:

  1. python -m pip install --upgrade pytube

  2. python3 -m pip install git+https://github.com/pytube/pytube

  3. Ran as ADMIN.

worked fine!

Heir answered 4/9, 2022 at 18:16 Comment(0)
S
5

I started a personal project a while ago that downloads YT videos (MP4's), and I ran into the same issue, among others. All of the answers were helpful, but it took like 2-3 of them combined to resolve my issue:

First, I had to download Git For Windows: (https://git-scm.com/download/win) Then, I downgraded my already installed PyTube package with the below command. This installs PyTube 10.9.3:

`python -m pip install git+https://github.com/Zeecka/pytube@fix_1060`

Finally, I re-installed the latest version of PyTube (this command installs the latest version):

`pip install --upgrade pytube`

Not sure exactly, what causes PyTube to flip out when you first install, but downgrading, then upgrading worked for me.

For any wondering, final-product code is as seen below. Videos downloaded at 720p, with their title as the name of the saved file.

from pytube import YouTube 
  
#where to save 
SAVE_PATH = "C:/YOUR/DESIRED/FILE/PATH/" 
  
#link of the video to be downloaded 
link = input("Enter URL >> ")
try:
    yt = YouTube(link)
    mp4_files = yt.streams.filter(file_extension="mp4")
    mp4_720p_files = mp4_files.get_by_resolution("720p")
    mp4_720p_files.download(SAVE_PATH) 
except Exception as e: 
    print("ERROR: ", e) 
        

Sources:

HTTP Error 410 'Gone' - https://www.youtube.com/watch?v=rrRuBrUrnCw

Git for Windows - https://git-scm.com/download/win

Second answered 10/11, 2022 at 16:28 Comment(2)
I had the same problem and of all the things I tested, this was what did it for me. Thanks a lot.Covert
Thanks bro nothing worked for me. Except for your answer. (i downgraded to pytube10.9.3)Lymph
R
2

This is a bug of the pytube version. You might install an older version of it. Upgrade pytube to 11+ will resolve the issue.

  • Open the terminal and execute the following command to upgrade the version

    pip install --upgrade pytube
    

enter image description here

https://github.com/pytube/pytube/issues/1243

Roter answered 28/9, 2022 at 5:16 Comment(0)
A
2

How I solved the error

  1. First uninstall your pytube using pip

    pip uninstall pytube

  2. Clear pip cache

    pip cache purge

  3. Install pytube again

    pip install pytube

Almallah answered 31/12, 2023 at 11:41 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Waikiki
C
0

You can get the latest version from the official GitHub repository https://github.com/pytube/pytube

python3 -m pip install git+https://github.com/pytube/pytube

Updated to pytube 11.0.2

Cuspidation answered 22/12, 2021 at 15:34 Comment(0)
B
0

I am answering this because the solutions I found on the internet didn't work for me (the ones above too).

I even tried to install an other fix done ssuwani on GitHub using:

pip install git+https://github.com/ssuwani/pytube

(I use python 3.8.10 and Ubuntu 20.04.4 LTS)

I just used sudo su to enter admin mode, ran my program and it worked. To be honest, I don't know why, but if it can help that's nice :)

Warning, don't enter any commands when you're in admin mode because you could mess up your system

Bal answered 16/7, 2022 at 17:14 Comment(0)
E
0

Open CommandPrompt/Powershell or your OS equivalent as an 'Administrator':

  1. Uninstall the pytube library using (pip uninstall pytube)
  2. Clear the environment cache memory (pip cache purge)
  3. Install pytube again (pip install pytube).
Expediential answered 20/1 at 20:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.