Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] urllib.error.HTTPError: HTTP Error 403: Forbidden #1916

Open
emcf opened this issue May 4, 2024 · 3 comments
Open

[BUG] urllib.error.HTTPError: HTTP Error 403: Forbidden #1916

emcf opened this issue May 4, 2024 · 3 comments
Labels

Comments

@emcf
Copy link

emcf commented May 4, 2024

I am on the latest version of pytube.

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Please provide the following information:

from pytube import YouTube
youtube_url = "https://www.youtube.com/watch?v=wUEr7TayrmU"
temp_dir = "youtube_temp"
filename = "temp_video.mp4"
yt = YouTube(youtube_url)
stream = yt.streams.filter(progressive=True, file_extension='mp4').first()
stream.download(temp_dir, filename=filename)

Expected behavior
Expected no exception to be raised.

Output

Traceback (most recent call last):
  File "/home/runner/work/thepipe/thepipe/tests/test_thepipe.py", line 51, in test_extract_youtube
    chunks = extractor.extract_from_source("https://www.youtube.com/watch?v=wUEr7TayrmU")
  File "/home/runner/work/thepipe/thepipe/thepipe_api/extractor.py", line 55, in extract_from_source
    return extract_youtube(youtube_url=source, text_only=text_only, verbose=verbose)
  File "/home/runner/work/thepipe/thepipe/thepipe_api/extractor.py", line 376, in extract_youtube
    stream.download(temp_dir, filename=filename)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/pytube/streams.py", line 309, in download
    bytes_remaining = self.filesize
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/pytube/streams.py", line 157, in filesize
    self._filesize = request.filesize(self.url)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/pytube/request.py", line 204, in filesize
    return int(head(url)["content-length"])
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/pytube/request.py", line 268, in head
    response_headers = _execute_request(url, method="HEAD").info()
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/pytube/request.py", line 37, in _execute_request
    return urlopen(request, timeout=timeout)  # nosec
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/urllib/request.py", line 525, in open
    response = meth(req, response)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/urllib/request.py", line 634, in http_response
    response = self.parent.error(
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/urllib/request.py", line 563, in error
    return self._call_chain(*args)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/urllib/request.py", line 496, in _call_chain
    result = func(*args)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/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 403: Forbidden

System information
Default github actions server

EDIT: It seems this same error prompted the creation of a similar issue which may be resolved by setting a User-Agent in the request header.

@emcf emcf added the bug label May 4, 2024
Copy link

github-actions bot commented May 4, 2024

Thank you for contributing to PyTube. Please remember to reference Contributing.md

@morris-choga
Copy link

Experienced this error a while back. After a few days everything was working normally. After my research i came to the conclusion that this is a restriction by youtube on your ip address or device they will eventually lift it

@emcf
Copy link
Author

emcf commented May 22, 2024

Experienced this error a while back. After a few days everything was working normally. After my research i came to the conclusion that this is a restriction by youtube on your ip address or device they will eventually lift it

Coming back here to say that I've had pretty much the same experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants