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)

Most upvoted comments

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 be base_headers = {"User-Agent": "Mozilla/5.0", "accept-language": "en-US,en"} instead of base_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.

pip install pytube==10.4.1

It looks like not fixed yet.

I installed pytube 9.7.0:

python3 -m pip install --upgrade "git+https://github.com/nficano/pytube.git"

I then tested again the same content:

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

Error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../python3.6/site-packages/pytube/__main__.py", line 103, in __init__
    self.descramble()
  File ".../python3.6/site-packages/pytube/__main__.py", line 123, in descramble
    self.player_config_args = get_ytplayer_config(self.watch_html)[
  File ".../python3.6/site-packages/pytube/extract.py", line 206, in get_ytplayer_config
    caller="get_ytplayer_config", pattern="config_patterns"
pytube.exceptions.RegexMatchError: get_ytplayer_config: could not find match for config_patterns

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 line youtube = 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 with python3 -m pip install git+https://github.com/nficano/pytube.git?

@tfdahlin thanks a lot, your consideration is correct and your suggestion fixes the problem!

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
>>> YouTube('https://www.youtube.com/watch?v=5YceQ8YqYMc')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../.local/lib/python3.6/site-packages/pytube/__main__.py", line 103, in __init__
    self.prefetch()
  File ".../.local/lib/python3.6/site-packages/pytube/__main__.py", line 177, in prefetch
    raise RecordingUnavailable(video_id=self.video_id)
pytube.exceptions.RecordingUnavailable: 5YceQ8YqYMc does not have a live stream recording available
>>>

@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!