-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
urllib.error.HTTPError: HTTP Error 403: Forbidden #399
Comments
I am having the same problem, but for me, it is random whether the same youtube link will generate a 403 or not. My current testing links are: |
It's a hack of a fix, but this is how I've got mine working for now (I'm running in python 2.7, you may need to fiddle depending on your version): And above line 21 (response = urlopen(url)): And then replace the line below: |
Just tested the solution, keeps randomly giving 403, and then working again. |
@Waarbubble : you mean you tested @Nowbob's solution? |
yes |
Yeah I was having the same "sometimes it works sometimes it doesn't" problem, but it's the best I could come up with in a short time. |
It was worth a try. |
I'm doing something wrong... then line 22/23: now I'm getting this error:
File "C:\Users\janvo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pytube\request.py", line 22, in get |
If you are using python 3 the fourth line needs to be from urllib.request import Request and then line 22 will need a capital R in request |
Thanks...I changed it now. It's behaving the same way...three times I got the 403-error and then it worked. |
Getting the same error. I tried all the solutions above. And some works and some don't. |
This got much more frequent for me today for some reason. The above solutions do not seem to work for the new cases. Example video https://www.youtube.com/watch?v=ZYoUXaU81Gk |
I believe I've managed to fix this by changing |
The solution works for me, no more random 403 |
Neither suggested solution fixes my test video https://www.youtube.com/watch?v=ZYoUXaU81Gk |
@danielgordon10 What error are you getting? I just tried downloading that link and it seems to be working with the &sig= fix.
|
So I am able to get the stream but I can't download it. import pytube
video_url = 'https://www.youtube.com/watch?v=ZYoUXaU81Gk'
yt = pytube.YouTube(video_url)
streams = yt.streams
streams = (
streams.filter(progressive=True, custom_filter_functions=[lambda x: x.resolution is not None])
.order_by("resolution")
.all()
)
stream = streams[0]
video = stream.download() Then I get the
|
I've only used this in CLI before so I'm not sure, my guess would be to check if it's importing the correct one. |
It works fine for other videos... |
I think I have a working fix now for this and a related issue (#392). It's not pretty, but it seems to get the job done. if ('signature=' in url or
('s' not in stream and
('&sig=' in url or '&lsig=' in url))):
# For certain videos, YouTube will just provide them pre-signed, in
# which case there's no real magic to download them and we can skip
# the whole signature descrambling entirely.
logger.debug('signature found, skip decipher')
continue
if js is not None:
signature = cipher.get_signature(js, stream['s'])
else:
# signature not present in url (line 33), need js to descramble
# TypeError caught in __main__
raise TypeError('JS is None')
logger.debug(
'finished descrambling signature for itag=%s\n%s',
stream['itag'], pprint.pformat(
{
's': stream['s'],
'signature': signature,
}, indent=2,
),
)
stream_manifest[i]['url'] = url + '&sig=' + signature |
I tried the first fix from @Nowbob, but the problem persisted. |
still have that error !? |
It's work thank you! and stream_manifest[i]['url'] = url + '&signature=' + signature and change pattern in cipher.py I forget this issue number, someone can help me to link? |
I tried for 15 minutes before realising that : for the mixins.py fix, you have to replace the whole snippet, not just replace Now it works, thanks a lot ! |
@gitethis 's solutions work, and tried it on my scripts, however, here's a slight tweak for python3 users: in request.py instead of: use this: /ogs |
Seeing as how this appears to be solved with the changes described in various comments, did anyone create a pull request already? I noticed one while quickly scanning this issue, but that one's CI tests failed. |
This also worked very well for me. |
I changed both mixins.py and cipher.py, but I still got HTTPError: Forbidden |
I use Python 3.7 and pytube 9.5.2 with win 10. |
I tried this in Windows 10, and it did finally work. Python 3.7.4, PyTube 9.5.2 with the above 2 patches. I also had to apply the title retrieval patch in main.py and streams.py as outlined by @ogspeace. Did not have to mess with urllib for whatever reason, but maybe just got lucky on the ~50 videos I've tried. |
did you use also my patches on "title" retrieval for main.py and streams.py, as outlined and confirmed by @ogspeace ? |
To keep things clear here, the 'title' retrieval patches fixed a separate issue, e.g. using |
For me, the errors are not occurring randomly. They always seem to occur when I attempt to download music videos. |
Not working |
How do i find this mixins py file? |
I tried @Nowbob fix but does'nt work, it says Request not defined. |
You’re missing the Request module in your python installation.
Sent with the great iPhone
… On 3 Dec 2019, at 15:17, Yash ***@***.***> wrote:
I tried @Nowbob fix but does'nt work, it says Request not defined.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
@YashKarthik @gittethis fixed in pytube3: https://github.com/hbmartin/pytube3/ |
Cannot work with the solutions in this thread Mac OS Mojave, Python 3.7 |
@yijun-li-20 what url are you looking at? what version of pytube are you using? |
hi, pytube3 9.6.4 get urllib.error.HTTPError: HTTP Error 403: Forbidden on this video: |
Where is the mixins.py file in urllib3? |
I am using Python3 and the following changes worked for me: So, you basically study the structure of your URL. In my case since I'm working with Youtube Data API and hence a sample URL for me looked like: I used the urllib.parse library and then generated the above URL using the strategy below: params = {'part':'snippet','id':VIDEO_KEY_goes_here', 'key':'YOUR_API_KEY_goes_here'} |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
any chance get your help in privet? on e mail maybe? |
This issue is still persistent to this date and what's more is that the Here is the video I am consistently getting errors with: https://youtube.com/watch?v=56tBagXBH5A I was suggested to switch from |
Hello. So for some reason for me |
Hi all,
I'm aware that there are some older issues with the same error, howevery I thought I would just give it a try. For some videos (like this one: https://www.youtube.com/watch?v=393C3pr2ioY ) I get a 403 error...others work fine though. Do you know of any workaround for that? I saw this thread in the older issue https://stackoverflow.com/questions/16627227/http-error-403-in-python-3-web-scraping but I'm not good enough in Python to find the right spot to implement it. Any help would be appreciated.
PS: I already updated to the most current version (9.5.0).
The text was updated successfully, but these errors were encountered: