pytube: NEW ISSUE: Error to download (AttributeError: 'NoneType' object has no attribute 'span')

New issue around to download audio and videos from Youtube.

Here is the code to test:

from pytube import YouTube


youtube_episode_id = 'MEmU-VGM62M'   # long

yt = YouTube(f'https://www.youtube.com/watch?v={youtube_episode_id}')

ITAG = 22

stream = yt.streams.get_by_itag(ITAG)
stream.download(output_path='cache', filename=f'{youtube_episode_id}.mp4', skip_existing=True, max_retries=0)

Actual result:

Traceback (most recent call last):
  File "f:\test\teste11.py", line 12, in <module>
    link = yt.streams.get_by_itag(ITAG).url
  File "f:\test\venv\lib\site-packages\pytube\__main__.py", line 316, in streams
    return StreamQuery(self.fmt_streams)
  File "f:\test\venv\lib\site-packages\pytube\__main__.py", line 181, in fmt_streams
    extract.apply_signature(stream_manifest, self.vid_info, self.js)
  File "f:\test\venv\lib\site-packages\pytube\extract.py", line 411, in apply_signature
    cipher = Cipher(js=js)
  File "f:\test\venv\lib\site-packages\pytube\cipher.py", line 43, in __init__
    self.throttling_plan = get_throttling_plan(js)
  File "f:\test\venv\lib\site-packages\pytube\cipher.py", line 427, in get_throttling_plan
    transform_plan_raw = find_object_from_startpoint(raw_code, match.span()[1] - 1)
AttributeError: 'NoneType' object has no attribute 'span'

Process finished with exit code 1

I tested with different Itags and all have the same problem.

About this issue

  • Original URL
  • State: open
  • Created 9 months ago
  • Reactions: 3
  • Comments: 17

Commits related to this issue

Most upvoted comments

I was running into this issue as well. I patched this issue using a comment from a previous issue here: https://github.com/pytube/pytube/issues/1498#issuecomment-1472963944

I was running into this issue as well. I patched this issue using a comment from a previous issue here: #1498 (comment)

Worked for me as well in the short tests I did.

As a temporary fix I’ve updated my requirements.txt using the fix in the given branch.

# pytube==15.0.0 # unpatched error here as of 2023-09-27 https://github.com/abanand132/pytube/zipball/master

Same issue ‘AttributeError: NoneType’ object has no attribute span’

Does anyone have the fixed issue on a repository so I can pip install it?

same problem