Search code examples
pythonyoutubepytube

python pytube Error 'NoneType' object has no attribute 'span'


I was working with pytube yesterday and it was working without any problems. But suddenly it stopped today and I get this Error trying to get video streams. I tried to uninstall and install it again with different versions and nothing changed.

How to solve this?

Traceback (most recent call last):   File "<stdin>", line 1, in
<module  File
"C:\Users\2021\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py",
line 292, in streams
    return StreamQuery(self.fmt_streams)   File "C:\Users\2021\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py",
line 177, in fmt_streams
    extract.apply_signature(stream_manifest, self.vid_info, self.js)   File
"C:\Users\2021\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\extract.py",
line 409, in apply_signature
    cipher = Cipher(js=js)   File "C:\Users\2021\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py",
line 44, in __init__
    self.throttling_array = get_throttling_function_array(js)   File "C:\Users\2021\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py",
line 323, in get_throttling_function_array
    str_array = throttling_array_split(array_raw)   File "C:\Users\2021\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\parser.py",
line 158, in throttling_array_split
    match_start, match_end = match.span() AttributeError: 'NoneType' object has no attribute 'span'

Solution

  • pytube/pytube/parser.py

    Line 152 in f06e071

    func_regex = re.compile(r"function\([^)]+\)")
    

    should be changed to

    func_regex = re.compile(r"function\([^)]*\)")
    

    Edit:

    Change the + to a *