pytube: [BUG] RegexMatchError ?

Until now it’s worked perfectly, but now it’s showing a issue is this only for me or ?, can anyone help ty

Ignoring exception in on_message
Traceback (most recent call last):
File "/.local/lib/python3.9/site-packages/pytube/__main__.py", line 177, in fmt_streams
extract.apply_signature(stream_manifest, self.vid_info, self.js)
File "/.local/lib/python3.9/site-packages/pytube/extract.py", line 409, in apply_signature
cipher = Cipher(js=js)
File "/.local/lib/python3.9/site-packages/pytube/cipher.py", line 33, in __init__
raise RegexMatchError(
pytube.exceptions.RegexMatchError: __init__: could not find match for ^\\w+\\W

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 51
  • Comments: 46

Commits related to this issue

Most upvoted comments

I just updated the regex like this and it’s working: ^\$*\w+\W

image

I’m able to download the videos again.

Nope, i shifted my project to ytdlp ( ytdl forked, more advanced and get frequently updates ) . I got sick of pytube and its bugs on daily basis, my project got affected very bad with pytube. Now i am happy with more reliable and powerful lib ytdlp. Again i am not saying pytube is bad lib, But due to lack of updates by author and tons of bugs which is not getting fixed by months , i just shifted also i advise you same whosoever is running their project with pytube.

Thanks , this is not hate message for pytube, its just a my recommendation.

Prolly some new changes from youtube side

what worked for me was: in pytube/cipher.py change the line: var_regex = re.compile(r"^\w+\W") to var_regex = re.compile(r"^\$*\w+\W")

I just updated the regex like this and it’s working: ^\$*\w+\W

image

I’m able to download the videos again.

Thank you Juancho, I add this fix to PR #1193

Hi, anyone who’s using this library on some cloud-based platform like heroku can use my temporary repository till the next update. just in requirements.txt file replace pytube with git+https://github.com/ehsanbehdad/Pytube then you’ll be fine.

I just updated the regex like this and it’s working: ^\$*\w+\W

image

I’m able to download the videos again.

Sure it works perfectly, I tested it locally, but what if the app is deployed on Streamlit Cloud/sharing, Heroku … ?

Same. Raise exception from here: https://github.com/pytube/pytube/blob/master/pytube/cipher.py#L31 snapshot_issue_1199 The code for js changed. Reviewing the regular expression is a good start point. snapshot_issue_1199_2

What text editor is this @JavDomGom

top screenshot at least looks like PyCharm

HUGE you guys rock. Can’t wait for the patch

Yes, there are many PR to review and merge. As soon as the original code is up to date we should all update as well. Temporarily, whoever wants can use my fork with these problems already solved and if you prefer you can also apply the changes to your local version.

snapshot_issue_1199_3

I just updated the regex like this and it’s working: ^\$*\w+\W

image

I’m able to download the videos again.

Beaaauty! I tried but forgot the * between the $ and w! Time to go review my regular expressions! Cheers

is pytube is working for anyone, Please share pytube patched branch so that we will be able to install through pip

HUGE you guys rock. Can’t wait for the patch

Yes, there are many PR to review and merge. As soon as the original code is up to date we should all update as well. Temporarily, whoever wants can use my fork with these problems already solved and if you prefer you can also apply the changes to your local version.

snapshot_issue_1199_3

great work, thankyou so much!!!

Same. Raise exception from here: https://github.com/pytube/pytube/blob/master/pytube/cipher.py#L31

snapshot_issue_1199

The code for js changed. Reviewing the regular expression is a good start point.

snapshot_issue_1199_2

I wrote the code to fix this bug in this PR https://github.com/pytube/pytube/pull/1336 I tested it locally and it worked for me. Until this PR gets merged you can manually edit the cipher file on line 30 and change the regular exp as mentioned in this stack overflow answer https://stackoverflow.com/a/70777385

Some guy showed this image. Which file is that, and where can i access it image

https://github.com/pytube/pytube/blob/2e307d8d615ef30aa837fe2275954146dab07ca6/pytube/cipher.py#L30

Hi, anyone who’s using this library on some cloud-based platform like heroku can use my temporary repository till the next update. just in requirements.txt file replace pytube with git+https://github.com/ehsanbehdad/Pytube then you’ll be fine.

Thank you @ehsanbehdad, this worked for me!

Hi, you can use my temporary repository for your heroku app till the next update. just in requirements.txt file replace pytube with git+https://github.com/ehsanbehdad/Pytube then you’ll be fine.

Thank you Ehsan that’s great will try that !

Please Anyone share the branch in which it is patched

Sure it works perfectly, I tested it locally, but what if the app is deployed on Streamlit Cloud/sharing, Heroku … ?

https://github.com/pytube/pytube/issues/1199#issuecomment-1017190777

Update the library with the changes you made and then later we solve the problem of the kit… We want a solution All telegram bots and Windows programs are stopped … Update the library with what you have solved

@JavDomGom please add another change to your PR:

# pytube/parser.py, line 152
-    func_regex = re.compile(r"function\([^)]+\)")
+    func_regex = re.compile(r"function\([^)]*\)")

this fixes another exception occurring during audio fetching:

    yt.streams.get_by_itag(140).download(directory, file_name)
  File "/home/artur/.venv/lib/python3.8/site-packages/pytube/__main__.py", line 292, in streams
    return StreamQuery(self.fmt_streams)
  File "/home/artur/.venv/lib/python3.8/site-packages/pytube/__main__.py", line 177, in fmt_streams
    extract.apply_signature(stream_manifest, self.vid_info, self.js)
  File "/home/artur/.venv/lib/python3.8/site-packages/pytube/extract.py", line 409, in apply_signature
    cipher = Cipher(js=js)
  File "/home/artur/.venv/lib/python3.8/site-packages/pytube/cipher.py", line 44, in __init__
    self.throttling_array = get_throttling_function_array(js)
  File "/home/artur/.venv/lib/python3.8/site-packages/pytube/cipher.py", line 323, in get_throttling_function_array
    str_array = throttling_array_split(array_raw)
  File "/home/artur/.venv/lib/python3.8/site-packages/pytube/parser.py", line 158, in throttling_array_split
    match_start, match_end = match.span()
AttributeError: 'NoneType' object has no attribute 'span'

Hi @arturtamborski, this is already solved in the current version: https://github.com/JavDomGom/pytube/blob/master/pytube/parser.py#L152

lmao, got the same error and wanted to open an issue. Literally yesterday everything was fine