Solved — pytube.exceptions.RegexMatchError: __init__: could not find match for ^\w+\W

RegexMatchError python version: 3.8.10 pytube version: 11.0.2

Flutter Developer

--

Code:

from pytube import YouTube

yt = YouTube('https://www.youtube.com/watch?v=aQNrG7ag2G4')
stream = yt.streams.filter(file_extension='mp4')

Error:

Traceback (most recent call last):
File ".\test.py", line 4, in <module>
stream = yt.streams.filter(file_extension='mp4')
File "C:\Users\logan\AppData\Local\Programs\Python\Python38\lib\site-packages\pytube\__main__.py", line 292, in streams
return StreamQuery(self.fmt_streams)
File "C:\Users\logan\AppData\Local\Programs\Python\Python38\lib\site-packages\pytube\__main__.py", line 184, in fmt_streams
extract.apply_signature(stream_manifest, self.vid_info, self.js)
File "C:\Users\logan\AppData\Local\Programs\Python\Python38\lib\site-packages\pytube\extract.py", line 409, in apply_signature
cipher = Cipher(js=js)
File "C:\Users\logan\AppData\Local\Programs\Python\Python38\lib\site-packages\pytube\cipher.py", line 33, in __init__
raise RegexMatchError(
pytube.exceptions.RegexMatchError: __init__: could not find match for ^\w+\W

Solution:

In order to solve the problem, you should go in the cipher.py file and replace the line 30, which is:

var_regex = re.compile(r"^\w+\W")

With this line:

var_regex = re.compile(r"^\$*\w+\W")

Hope this helped 🙏

Support me by becoming a Medium member 🥳, and get access to unique programming articles that will enhance you skills.

Become a Medium member — 🖖 Live long and prosper 🖖

--

--