Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pytube issue: AttributeError 'NoneType' object has no attribute 'span' #1499

Open
Were-Logan-0110 opened this issue Mar 16, 2023 · 13 comments
Open
Labels

Comments

@Were-Logan-0110
Copy link

Before creating an issue

I do use the latest version of pytube and tried to install other versions and same error

Description:

I am trying to use the getResOfVideos function to get the available resolutions and data about videos in a YouTube playlist. However, I am encountering an error message that says AttributeError: 'NoneType' object has no attribute 'span'. I tried running the code on Colab and GitHub Codespaces, but I get the same error.

To Reproduce

The function

def getResOfVideos(playlist_4_url):
    resolution_results = []
    video_data_results = []
    available_resolutions = set()

    for video_url in playlist_4_url:
        video = YouTube(video_url)
        video_resolutions = set()
        for stream in video.streams:
            video_resolutions.add(stream.resolution)
        video_resolutions.discard(None)
        resolution_results.append(video_resolutions)
        video_data_results.append([
            video.title,
            "{:.2f}".format(video.length / 60),
            video.description,
            video.publish_date.strftime('%Y-%m-%d'),
            f'{video.views/1000}K',
            video.thumbnail_url
        ])

    if len(resolution_results) > 0:
        available_resolutions = set(resolution_results[0])
        for video_resolutions in resolution_results[1:]:
            available_resolutions = available_resolutions.intersection(video_resolutions)

    return [list(available_resolutions), video_data_results]

Expected behavior

The getResOfVideos function should return the available resolutions and data about the videos in the given YouTube playlist URLS. The function should not raise any attribute error and should be able to handle all valid YouTube playlist URLs.

Output

AttributeError Traceback (most recent call last) in
92 pl = Playlist("https://www.youtube.com/watch?v=-nXrJmI5JjU&list=PLMOobVGrchXNbTrmUb8_3yZNscK3rle3B")
93 print(pl.video_urls)
---> 94 print(getResOfVideos(pl.video_urls))
95 getinp = input("res?: ")
96 dl = Downloader()
5 frames
in getResOfVideos(playlist_4_url)
59 video = YouTube(video_url)
60 video_resolutions = set()
---> 61 for stream in video.streams:
62 video_resolutions.add(stream.resolution)
63 video_resolutions.discard(None)
/usr/local/lib/python3.9/dist-packages/pytube/main.py in streams(self)
/usr/local/lib/python3.9/dist-packages/pytube/main.py in fmt_streams(self)
/usr/local/lib/python3.9/dist-packages/pytube/extract.py in apply_signature(stream_manifest, vid_info, js)
/usr/local/lib/python3.9/dist-packages/pytube/cipher.py in init(self, js)
/usr/local/lib/python3.9/dist-packages/pytube/cipher.py in get_throttling_plan(js)
AttributeError: 'NoneType' object has no attribute 'span'

System information

Google Colab , Github CodeSpace

  • Python version (run python --version)
  • Pytube version (Latest)
  • Command used : pip install pytube , pip install git+https://github.com/siupy-creator/fixed-pytube
@github-actions
Copy link

Thank you for contributing to PyTube. Please remember to reference Contributing.md

@RichardeLira
Copy link

The same error here

@fbereche
Copy link

I'm having this error too.

@jianlin666
Copy link

The same error here

@rodolflying
Copy link

same for me, dowloading audio. i have seen older fixes but nothing worked. probably some temporal youtube servers error.

@rodolflying
Copy link

its already fixed : #1498.

look for the answer of dark9ive. i cite here to the team to close the duplicated issue.

Solution that worked for me:

simply modifying {home}/.local/lib/python3.7/site-packages/pytube/cipher.py
Line 411

transform_plan_raw = find_object_from_startpoint(raw_code, match.span()[1] - 1)
to

transform_plan_raw = js

@jgillip
Copy link

jgillip commented Mar 17, 2023

its already fixed : #1498.

look for the answer of dark9ive. i cite here to the team to close the duplicated issue.

Solution that worked for me:

simply modifying {home}/.local/lib/python3.7/site-packages/pytube/cipher.py Line 411

transform_plan_raw = find_object_from_startpoint(raw_code, match.span()[1] - 1) to

transform_plan_raw = js

Confirmed that this got around the issue.

@machaudhary
Copy link

machaudhary commented Mar 17, 2023

I am able to resolve this issue locally. But I am also using pytube in AWS Batch which uses a docker image.

Can anyone help me how to change this line of code in docker image?
`transform_plan_raw = find_object_from_startpoint(raw_code, match.span()[1] - 1) to

transform_plan_raw = js`

Earlier I was doing pip3 install pytube. But since a new version is not available corresponding to change, how should I proceed?

@joaomsimoes
Copy link

joaomsimoes commented Mar 17, 2023

I am able to resolve this issue locally. But I am also using pytube in AWS Batch which uses a docker image.

Can anyone help me how to change this line of code in docker image? `transform_plan_raw = find_object_from_startpoint(raw_code, match.span()[1] - 1) to

transform_plan_raw = js`

Earlier I was doing pip3 install pytube. But since a new version is not available corresponding to change, how should I proceed?

If you have access to the command line just do like this:

Go to this folder:
/home/<your_project>/.local/lib/python3.7/site-packages/pytube

Make the changes:
vim cipher.py

@davidVasquezO
Copy link

Yo también estoy teniendo este problema del error AttributeError: 'NoneType' object has no attribute 'span' al usar pytube.

He visto la solución propuesta de modificar el archivo cipher.py, pero no me sirve en mi caso porque estoy trabajando en Google Colab.

@antoni0z
Copy link

Yo también estoy teniendo este problema del error AttributeError: 'NoneType' object has no attribute 'span' al usar pytube.

He visto la solución propuesta de modificar el archivo cipher.py, pero no me sirve en mi caso porque estoy trabajando en Google Colab.

Yo tambien estoy en Colab, he buscado sobre como modificar los archivos que se importan a colab pero al modificarlo parece que no se cambia. Si encuentras una solucion comentame.

@davidVasquezO
Copy link

Yo también estoy teniendo este problema del error AttributeError: 'NoneType' object has no attribute 'span' al usar pytube.
He visto la solución propuesta de modificar el archivo cipher.py, pero no me sirve en mi caso porque estoy trabajando en Google Colab.

Yo tambien estoy en Colab, he buscado sobre como modificar los archivos que se importan a colab pero al modificarlo parece que no se cambia. Si encuentras una solucion comentame.

En Google colab no es una buena solución modificarlos, ya que las librerías instaladas en el entorno son temporales y se borran al poco tiempo.

Lo que puedes hacer crear el proyecto en un entorno virtual en local y ahí si hacer la modificación de cypher.py, la solución te puede durar un poco más.

Saludos.

@JohnBartlett
Copy link

JohnBartlett commented Mar 20, 2023

FYI,

on my macOS, I found the file in:

/opt/homebrew/lib/python3.11/site-packages/pytube/

And yes, that fixed the issue. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests