r/pythonhelp • • Feb 22 '22

Issue with URL pasting in Python

Hey there, so recently I've been trying to make a Youtube Video Downloader, and for some reason when I input a FULL url it shows an error that goes something like: File "c:\Users\User\OneDrive\Desktop\The Youtube Video Downloader.py", line 10, in <module> video = YouTube(url)

Anyways Here Is The Script:

from pytube import YouTube

import time

print("The Youtube Video Downloader")

time.sleep(0.2)

print("\nBy: ViridianTelamon.")

time.sleep(0.2)

#url = input("\nInput The Full Url For The Youtube Video That You Want To Download (Shortened Urls Will Not Work): ")

url = input("\nInput The Url For The Video: ")

#print(f"Url Inputted: {url}")

#print(url)

video = YouTube(url)

time.sleep(0.2)

print("\n----------Video Title----------")

time.sleep(0.2)

print(video.title)

time.sleep(0.2)

print("\n----------Video Thumbnail Url----------")

time.sleep(0.2)

print(video.thumbnail_url)

time.sleep(2)

print("\n----------Video Download----------")

time.sleep(0.2)

video = video.streams.get_highest_resolution

video.download()

print("\nVideo Successful Downloaded In The Same Directory As This Script.")

0 Upvotes

13 comments sorted by

View all comments

1

u/[deleted] Feb 22 '22

As the \ symbol has a special meaning in Python, you may need to either escape the backslashes, e.g. "\\text" instead of "\text", or use raw strings, r"\text".

Need to see full traceback to check what the exact problem is.

EDIT: hit save too soon

1

u/ViridianGuy Feb 22 '22

Okay got it:

Traceback (most recent call last): File "c:\Users\User\OneDrive\Desktop\The Youtube Video Downloader.py", line 15, in <module> video = YouTube(url) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube__main__.py", line 91, in __init__ self.prefetch() File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube__main__.py", line 181, in prefetch self.vid_info_raw = request.get(self.vid_info_url) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\request.py", line 36, in get return _execute_request(url).read().decode("utf-8") File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\request.py", line 24, in _execute_request return urlopen(request) # nosec File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 216, in urlopen return opener.open(url, data, timeout) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 525, in open response = meth(req, response) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 634, in http_response response = self.parent.error( File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 557, in error result = self._call_chain(*args) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 496, in _call_chain result = func(*args) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 749, in http_error_302 return self.parent.open(new, timeout=req.timeout) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 525, in open response = meth(req, response) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 634, in http_response response = self.parent.error( File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 563, in error return self._call_chain(*args) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 496, in _call_chain result = func(*args) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 643, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp)urllib.error.HTTPError: HTTP Error 410: GonePS C:\Users\User\OneDrive\Desktop>

1

u/MT1961 Feb 22 '22

A 410 error indicates that the target resource is no longer available at the server. This was a known issue in PyTube for a while, apparently fixed in version 11.0:

https://lifesaver.codes/answer/bug-http-error-410-gone-1076

You might try the upgrade suggested there.

1

u/ViridianGuy Feb 22 '22

How would you update it?

1

u/MT1961 Feb 23 '22

You use something like this:

pip install --upgrade <package-name>

You can add --user if you want it in your user directory instead of system wide.

1

u/ViridianGuy Feb 23 '22

This is what I got:

C:\Users\User>pip install --upgrade

PyTubeRequirement already satisfied: PyTube in c:\users\user\appdata\local\programs\python\python310\lib\site-packages (12.0.0)

1

u/ViridianGuy Feb 23 '22

Now I am getting this error:

File "c:\Users\User\OneDrive\Desktop\The Youtube Video Downloader.py", line 15, in <module> video = YouTube(url) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube__main__.py", line 91, in __init__ self.prefetch() File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube__main__.py", line 181, in prefetch self.vid_info_raw = request.get(self.vid_info_url) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\request.py", line 36, in get return _execute_request(url).read().decode("utf-8") File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\request.py", line 24, in _execute_request return urlopen(request) # nosec File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 216, in urlopen return opener.open(url, data, timeout) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 525, in open response = meth(req, response) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 634, in http_response response = self.parent.error( File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 557, in error result = self._call_chain(*args) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 496, in _call_chain result = func(*args) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 749, in http_error_302 return self.parent.open(new, timeout=req.timeout) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 525, in open response = meth(req, response) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 634, in http_response response = self.parent.error( File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 563, in error return self._call_chain(*args) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 496, in _call_chain result = func(*args) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\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

1

u/MT1961 Feb 23 '22

Same error. Looks like a bug in the YouTube package.

1

u/ViridianGuy Feb 23 '22

Damn, I'm sorry for maybe being annoying but how would I fix this, I really want this script to work.

1

u/MT1961 Feb 23 '22

I understand, but I don't really know a lot about the YouTube api. Maybe find a different package?