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

HTTP Error 429: Too Many Requests #72

Open
arslandogar opened this issue Mar 26, 2020 · 22 comments
Open

HTTP Error 429: Too Many Requests #72

arslandogar opened this issue Mar 26, 2020 · 22 comments

Comments

@arslandogar
Copy link

arslandogar commented Mar 26, 2020

This piece of code

from pytube import YouTube
yt = YouTube('https://www.youtube.com/watch?v=tPEE9ZwTmy0')

Throws this error:

Traceback (most recent call last):
File "test.py", line 2, in
yt = YouTube('https://www.youtube.com/watch?v=tPEE9ZwTmy0')
File "/home/user/.local/lib/python3.6/site-packages/pytube/main.py", line 91, in init
self.prefetch()
File "/home/user/.local/lib/python3.6/site-packages/pytube/main.py", line 162, in prefetch
self.watch_html = request.get(url=self.watch_url)
File "/home/user/.local/lib/python3.6/site-packages/pytube/request.py", line 36, in get
return _execute_request(url).read().decode("utf-8")
File "/home/user/.local/lib/python3.6/site-packages/pytube/request.py", line 24, in _execute_request
return urlopen(request) # nosec
File "/usr/lib/python3.6/urllib/request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.6/urllib/request.py", line 532, in open
response = meth(req, response)
File "/usr/lib/python3.6/urllib/request.py", line 642, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python3.6/urllib/request.py", line 564, in error
result = self._call_chain(*args)
File "/usr/lib/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/usr/lib/python3.6/urllib/request.py", line 756, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "/usr/lib/python3.6/urllib/request.py", line 532, in open
response = meth(req, response)
File "/usr/lib/python3.6/urllib/request.py", line 642, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python3.6/urllib/request.py", line 570, in error
return self._call_chain(*args)
File "/usr/lib/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/usr/lib/python3.6/urllib/request.py", line 650, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 429: Too Many Requests

@swiftyy-mage
Copy link
Member

I will investigate this, my apologies for the delay.

@swiftyy-mage
Copy link
Member

swiftyy-mage commented Apr 3, 2020

I tested this on python 3.6, 3.7, 3.8 and I got no errors. Have you made any modifications and have you installed it the correct way?

@arslandogar
Copy link
Author

No, I have not made any changes. Just following instructions in readme.md.
Installed with this command pip3 install pytube3 --upgrade

Then in my code file I have
from pytube import YouTube
yt = YouTube('https://www.youtube.com/watch?v=tPEE9ZwTmy0')

Using Python 3.6.8 on Ubuntu 18.04

@swiftyy-mage
Copy link
Member

Does it raise this error every time? Does it raise this error for every video? This error code seems strange, kind of specific.

@arslandogar
Copy link
Author

The error occurs like 95% of the time and yes for every video.
And on random rare occasions, it does work alright.

@swiftyy-mage
Copy link
Member

swiftyy-mage commented Apr 5, 2020

I have used a new installation of Python 3.6.8 with Linux Mint 19.3 (which is based on Ubuntu 18.04), and have been totally unable to replicate this issue.
I have an idea of how to get it working though, have you tried using a VPN to use this package? If not I would recommend just making a free account of Proton VPN and using their command line tool, then once you are connected try using this package again. If using a VPN still doesn't work, try installing youtube-dl and see if that works. If youtube-dl doesn't work, I think it is your internet, if it does work but our package doesn't please let me know I will try again to help.

Once I had installed Python 3.6.8, I created a venv by running

python3.6 -m venv <path to virtual envirnment>

then activated the test environment with

source <path to virtual environment>/bin/activate

then installed pytube and updated to pytube3

pip3 install pytube
pip3 install pytube3 --upgrade

then I just ran the script and had no errors. I was able to download whatever youtube video I wanted.

Let me know how this goes anyway, I am eager to get this working for you.

@arslandogar
Copy link
Author

I tried using VPN and got the same error. youtube-dl also not working. So I guess it's my internet, is there anything that I can do about to make this work?

@swiftyy-mage
Copy link
Member

Is there anything you can do? Probably, but this is a little bit out of my knowledge 🤔. Which VPN are you using? And which country is your server in? I think it needs to be another country.

@arslandogar
Copy link
Author

arslandogar commented Apr 5, 2020

I am using Proton VPN, connected to fastest available server which happened to be in Netherlands.

@swiftyy-mage
Copy link
Member

I'm really sorry, I don't know how to help at the moment. Maybe try asking on some other website? People who know more about networks and the internet? I will keep thinking about this, if anything comes to mind I will post a reply here.

@swiftyy-mage
Copy link
Member

I have been doing some research, when you use youtube-dl have you tried using the flag --force-ipv4 ? People were having a similar issue ad that solved it for them?

@bigsandip
Copy link

Youtube-dl and pytube both works on local server but on a live website when you try downloading more then 3-4 videos it shows this error. I have been searching for the solution....iI found this but don't know how to do Check this

@arslandogar
Copy link
Author

youtube-dl worked after using the flag --force-ipv4.

@arslandogar
Copy link
Author

And now everything is working. I have tried 6 different videos with youtube-dl and it's working fine with and without --force-ipv4. Pytube is also working fine. But I don't know why.

@swiftyy-mage
Copy link
Member

@bigsandip When you say local server I don't know what you mean, is that a VPN? And about the solution you linked, I have never gone through the code in youtube-dl so I'm not sure how that program works. By the looks of it, you can save cookies in a config file. There is no option to do that in pytube currently, I will research this and see if I can add something similar in the future if it works for you. Did you try using the flag --force ipv4 in youtube-dl?

@swiftyy-mage
Copy link
Member

@arslandogar Well that is good everything is working now! I only know how pytube works, I thought I knew the basics of networks too but it looks like I need to do more research before I understand why this was not working for you.

@bigsandip
Copy link

bigsandip commented Apr 7, 2020

@swiftyy-mage I mean on http://127.0.0.1:8000/ . I haven't tried --force ipv4 but ill do now.

@bigsandip
Copy link

bigsandip commented Apr 7, 2020

@swiftyy-mage How do i use --force ipv4 in this:

ydl_opts = {
                'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio',

                'outtmpl': '~/Downloads/video.mp4',

                'noplaylist': True,
            }
            with youtube_dl.YoutubeDL(ydl_opts) as ydl:

                ydl.download([url])

@swiftyy-mage
Copy link
Member

@bigsandip I think it is just a command line flag, you just type it in as an argument when you use youtube-dl. I have never used youtube-dl though. I recommend trying to use a VPN.

@e2jk
Copy link

e2jk commented Apr 21, 2020

In case this could help, I ran this on my local computer without any VPN, no specific issues here:

Python 3.6.9 (default, Nov  7 2019, 10:44:02) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pytube import YouTube
>>> yt = YouTube('https://www.youtube.com/watch?v=tPEE9ZwTmy0')
>>> print(yt.title)
Shortest Video on Youtube
>>> 
KeyboardInterrupt
>>> 

$ uname -a
Linux daguerre 4.15.0-96-generic #97-Ubuntu SMP Wed Apr 1 03:25:46 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
$ python3 --version
Python 3.6.9
$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.4 LTS"

@ahtasham-07
Copy link

Try using this method: https://github.com/kazanture/YouPy

@StarkGang
Copy link

Try using this method: https://github.com/kazanture/YouPy

But I am using Heroku 😳😕

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

No branches or pull requests

6 participants