pytube: Error: get_ytplayer_config: could not find match for config_patterns
Installation (Python 3.6.9, pytube3-9.6.4):
pip3 uninstall -y pytube3
pip3 install git+https://github.com/nficano/pytube
python3
Test:
from pytube import YouTube
YouTube('https://www.youtube.com/watch?v=5YceQ8YqYMc')
Output including the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".local/lib/python3.6/site-packages/pytube/__main__.py", line 91, in __init__
self.prefetch()
File ".local/lib/python3.6/site-packages/pytube/__main__.py", line 183, in prefetch
self.js_url = extract.js_url(self.watch_html)
File ".local/lib/python3.6/site-packages/pytube/extract.py", line 143, in js_url
base_js = get_ytplayer_config(html)["assets"]["js"]
File ".local/lib/python3.6/site-packages/pytube/extract.py", line 202, in get_ytplayer_config
raise RegexMatchError(caller="get_ytplayer_config", pattern="config_patterns")
pytube.exceptions.RegexMatchError: get_ytplayer_config: could not find match for config_patterns```
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 6
- Comments: 33 (2 by maintainers)
hi @Ferdodonna it looks like you’re using a very old version of pytube based on the traceback you’re getting. Please run the following to uninstall pytube, and then reinstall from the source code:
python -m pip uninstall pytube pytube3 pytubex
python -m pip install git+https://github.com/nficano/pytube
@Ircama actually, I just had a thought about why that might be happening. I think this may be related to something that is being added in https://github.com/nficano/pytube/pull/683.
Your github profile says that you’re located in Italy, and I suspect that the page is being loaded in Italian, which means that the regex matches for checking if a video is unavailable aren’t finding the correct string.
Can you edit your copy of
request.py
and edit this line to bebase_headers = {"User-Agent": "Mozilla/5.0", "accept-language": "en-US,en"}
instead ofbase_headers = {"User-Agent": "Mozilla/5.0"}
and see if that fixes the problem?If you need help finding the filepath, you should be able to run the following to find the correct directory:
import os, pytube; print(os.path.dirname(pytube.__file__))
It works for me.
It looks like not fixed yet.
I installed pytube 9.7.0:
I then tested again the same content:
Error:
what worked for me:
Uninstalled the version 9 and did
pip install pytube==10.4.1
the pytube version 10.1.0 solves the problem.
I deleted “pytuebe” and “pytube3” folders in this location:
C:\Users\xxx\AppData\Local\Programs\Python\Python39\Lib\site-packages
and I installed it again with pip and somehow it works!Oh I assumed “pip install” would have the latest version available. Thank you now it works fine!
It still does not work for me although I updated pytube to 10.1.0. The error
get_ytplayer_config: could not find match for config_patterns, setconfig_patterns
still appears on the lineyoutube = pytube.YouTube(video_url)
Quick update on this: the PR that fixes the language issue is ready to go, just waiting on approval before merging it
@Ircama pytube is correctly raising a
RecordingUnavailable
exception when I run that test, did you make sure to reinstall pytube withpython3 -m pip install git+https://github.com/nficano/pytube.git
?@tfdahlin thanks a lot, your consideration is correct and your suggestion fixes the problem!
@Ferdodonna
pip install --upgrade <package>
may also help in the future 😃@P51KjMustang what’s the video url you’re trying to download?
Cool! That fix will hopefully be added to the actual pytube repository pretty soon, sorry that took so long to figure out!
@jihuun YouTube videos can be marked as “private”, which means they cannot be watched unless the person who posted the video directly shares the video with specific users. These are commonly used by companies for things like training videos that they want only their employees to be able to see.
Hi @Ircama @juancitro @roywang2011,
Can you try out the current version of the library to check if you’re still getting the above issue
Thanks!