Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

878
Visualizações
pytube: AttributeError: 'NoneType' object has no attribute 'span'

I just downloaded pytube (version 11.0.1) and started with this code snippet from here:

from pytube import YouTube
YouTube('https://youtu.be/9bZkp7q19f0').streams.first().download()

which gives this error:

AttributeError                            Traceback (most recent call last)
<ipython-input-29-0bfa08b87614> in <module>
----> 1 YouTube('https://youtu.be/9bZkp7q19f0').streams.first().download()

~/anaconda3/lib/python3.8/site-packages/pytube/__main__.py in streams(self)
    290         """
    291         self.check_availability()
--> 292         return StreamQuery(self.fmt_streams)
    293 
    294     @property

~/anaconda3/lib/python3.8/site-packages/pytube/__main__.py in fmt_streams(self)
    175         # https://github.com/pytube/pytube/issues/1054
    176         try:
--> 177             extract.apply_signature(stream_manifest, self.vid_info, self.js)                                                                            
    178         except exceptions.ExtractError:
    179             # To force an update to the js file, we clear the cache and retry                                                                           

~/anaconda3/lib/python3.8/site-packages/pytube/extract.py in apply_signature(stream_manifest, vid_info, js)                                                     
    407 
    408     """
--> 409     cipher = Cipher(js=js)
    410 
    411     for i, stream in enumerate(stream_manifest):

~/anaconda3/lib/python3.8/site-packages/pytube/cipher.py in __init__(self, js)
     42 
     43         self.throttling_plan = get_throttling_plan(js)
---> 44         self.throttling_array = get_throttling_function_array(js)
     45 
     46         self.calculated_n = None

~/anaconda3/lib/python3.8/site-packages/pytube/cipher.py in get_throttling_function_array(js)                                                                   
    321 
    322     array_raw = find_object_from_startpoint(raw_code, match.span()[1] - 1)                                                                              
--> 323     str_array = throttling_array_split(array_raw)
    324 
    325     converted_array = []

~/anaconda3/lib/python3.8/site-packages/pytube/parser.py in throttling_array_split(js_array)                                                                    
    156             # Handle functions separately. These can contain commas
    157             match = func_regex.search(curr_substring)
--> 158             match_start, match_end = match.span()
    159 
    160             function_text = find_object_from_startpoint(curr_substring, match.span()[1])

AttributeError: 'NoneType' object has no attribute 'span'

and I wonder why? Can anyone help me? I am running this snippet in an ipython console (IPython version 7.22.0) with Python 3.8.8 in a conda environment.

over 4 years ago · Santiago Trujillo
5 Respostas
Responde à pergunta

0

Found this issue, pytube v11.0.1. It's a little late for me, but if no one has submitted a fix tomorrow I'll check it out.

in C:\Python38\lib\site-packages\pytube\parser.py

Change this line:

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

to this:

152: func_regex = re.compile(r"function\([^)]?\)")

The issue is that the regex expects a function with an argument, but I guess youtube added some src that includes non-paramterized functions.

over 4 years ago · Santiago Trujillo Relatório

0

I had the same problem, I changed parser.py as in the answer above, just forked pytube lib on GitHub, and changed the file.

You can install pytube this way:

pip install git+https://github.com/baxterisme/pytube

Instead of:

pip install pytube
over 4 years ago · Santiago Trujillo Relatório

0

The most simplest solution can be:

  1. Go to the location where your python is installed (Mainly in : C:/Users/HP/appdata/local/programs/python)
  2. Search for pytube in the top right corner and delete all the pytube modules you see
  3. open your cmd (in administrative mode) here
  4. enter the command : pip install pytube
  5. it's done ✅ Now try running the code again [ ⭐I had the same issue and these steps solved it]
over 4 years ago · Santiago Trujillo Relatório

0

The problematic version was 11.0.1 and now has already been fixed, so you just need to upgrade to the newer version, and will be working fine again:

pip install --upgrade pytube
over 4 years ago · Santiago Trujillo Relatório

0

Edit:

I have tried to keep my solution up to date but I started to feel that pytube appears to have problems frequently and these bugs detrimentally affect my project. So I refactored it and started to use ytdlp library from now on. So at the time you are reading this, this solution might not work for you.

For the time being as we got this error again. You can try solution given here

Or

Make sure you in pytube/cipher.py on line 293:

You change

name = re.escape(get_throttling_function_name(js))

to

name = "hha"

Thanks Jeffery Williams

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda