pytube: [BUG]AttributeError: 'NoneType' object has no attribute 'span'

Before creating an issue I am on the latest version of pytube 11.0.2 my pip is at the latest version

Describe the bug So i can not download any videos using stream() method, I faced this issue yesterday as well and found a solution to change something in the cipher.py line 293, i did that and it worked for the rest of the day fine, when i woke up and tried to test it again the same error occurred even tho the line was changed and it is still changed as it was

To Reproduce Please provide the following information:

Expected behavior Well it should download the video!

Output

Traceback (most recent call last):
  File "J:\PycharmProjects\MyWorkProjects\work\.venv\lib\site-packages\discord\ext\commands\core.py", line 179, in wrapped
    ret = await coro(*args, **kwargs)
  File "J:\PycharmProjects\MyWorkProjects\work\SadisticFairyFolder\SadisticFairyCogs\music.py", line 496, in play
    files = await loop.run_in_executor(None, self.download_spotify_urls, ctx.guild.id,
  File "C:\Users\hp\AppData\Local\Programs\Python\Python39\lib\concurrent\futures\thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "J:\PycharmProjects\MyWorkProjects\work\SadisticFairyFolder\SadisticFairyCogs\music.py", line 82, in download_spotify_urls
    video = yt.streams.filter(only_audio=True).first()
  File "J:\PycharmProjects\MyWorkProjects\work\.venv\lib\site-packages\pytube\__main__.py", line 292, in streams
    return StreamQuery(self.fmt_streams)
  File "J:\PycharmProjects\MyWorkProjects\work\.venv\lib\site-packages\pytube\__main__.py", line 177, in fmt_streams
    extract.apply_signature(stream_manifest, self.vid_info, self.js)
  File "J:\PycharmProjects\MyWorkProjects\work\.venv\lib\site-packages\pytube\extract.py", line 409, in apply_signature
    cipher = Cipher(js=js)
  File "J:\PycharmProjects\MyWorkProjects\work\.venv\lib\site-packages\pytube\cipher.py", line 43, in __init__
    self.throttling_plan = get_throttling_plan(js)
  File "J:\PycharmProjects\MyWorkProjects\work\.venv\lib\site-packages\pytube\cipher.py", line 387, in get_throttling_plan
    raw_code = get_throttling_function_code(js)
  File "J:\PycharmProjects\MyWorkProjects\work\.venv\lib\site-packages\pytube\cipher.py", line 301, in get_throttling_function_code
    code_lines_list = find_object_from_startpoint(js, match.span()[1]).split('\n')
AttributeError: 'NoneType' object has no attribute 'span'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "J:\PycharmProjects\MyWorkProjects\work\.venv\lib\site-packages\discord\ext\commands\bot.py", line 335, in invoke
    await ctx.command.invoke(ctx)
  File "J:\PycharmProjects\MyWorkProjects\work\.venv\lib\site-packages\discord\ext\commands\core.py", line 916, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "J:\PycharmProjects\MyWorkProjects\work\.venv\lib\site-packages\discord\ext\commands\core.py", line 188, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'span'

System information Please provide the following information:

  • Python 3.9.1 -Pytube 11.0.2
  • pip install git+https://github.com/baxterisme/pytube

About this issue

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

Commits related to this issue

Most upvoted comments

This is a duplicate of #1225. The temporary fix is to change the name from ’ name = “iha” ’ to ’ name = “jha” ’

Well “jha” no longer works lol, it worked at first and everything going smoothly but yeah, it’s temporary fix after all

Will it even get fixed ? I saw someone saying its a dead library.

still, this bug irritates any solutions 😦 /?

So I am jumping in as I too just tried to start learning pytube today (bad day to start it seems), mostly so when a patch is pushed I will (hopefully) notice. I am running pytube 11.0.2 and python 3.8.10. setting the name variable in cipher.py seems to have worked for the first video I am testing with, I changed the code to:

#name = re.escape(get_throttling_function_name(js))
name = "jha"

That seems to have done it without any of the regex changes. The fix worked for an entire playlist of videos to be downloaded

And editing to add that as of 2-4-22 this fix no longer works

I notice that ‘jha’ works for some videos. But a new error occurs when I tried to download https://www.youtube.com/watch?v=-hLsqlKm-A4

image

Yes i have noticed many others encountered this kind of issue but when i tried the fixes they mentioned, it only worked for yesterday but it stopped today even tho the fixes have been done one of the fixes was to change line 293 in cipher.py to name = “iha” the other one was to change this func_regex = re.compile(r"function\([^)]+\)") to func_regex = re.compile(r"function\([^)]*\)") but it shows at me like this func_regex = re.compile(r"function\([^)]?\)") now