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

Issue when downloading videos, AttributeError: 'NoneType' object has no attribute 'get' #400

Open
FreekCool opened this issue Jan 2, 2025 · 6 comments
Labels
bug Something isn't working

Comments

@FreekCool
Copy link

FreekCool commented Jan 2, 2025

🛑 DO NOT REMOVE OR SKIP THIS ISSUE TEMPLATE 🛑

Issues with incomplete or missing information will be closed automatically.


🐞 Bug Description

Provide a clear and concise description of the bug.

Hi there, I am trying to download youtube videos in the lowest quality, as the code below shows. Only, for almost all videos I am having the following error:

Traceback (most recent call last):
  File "/my/path/my_python_file.py", line 266, in <module>
    download_youtube_video(video_link, LOCAL_VIDEOS_PATH, f'{video_id}.mp4', on_progress)
  File "/my/path/download_utils.py", line 159, in download_youtube_video
    ys = yt.streams.get_lowest_resolution()
  File "/my/path/python3.8/site-packages/pytubefix/__main__.py", line 649, in streams
    self.check_availability()
  File "/my/path/.local/lib/python3.8/site-packages/pytubefix/__main__.py", line 316, in check_availability
    status, messages = extract.playability_status(self.vid_info)
  File "/my/path/.local/lib/python3.8/site-packages/pytubefix/extract.py", line 106, in playability_status
    status_dict = player_response.get('playabilityStatus', {})
AttributeError: 'NoneType' object has no attribute 'get'

For example, this happens for a video with id qoTa_vfO8-4 and full link https://www.youtube.com/watch?v=qoTa_vfO8-4. The weird thing is that it works when I manually do it in the python3 terminal prompt. Also, these videos are not banned or only privately accessible. It is also worth noting that most of these videos come from Chinese content creators.


🔢 Code Snippet

Include the minimal code snippet that reproduces the issue.

import os
from pytubefix import YouTube
from pytubefix.cli import on_progress

def download_youtube_video(video_url, output_path, video_filename, on_progress):
    print(f'Download using po token')
    video_url = extract_video_url(video_url)
    print(f'Video URL: {video_url}')
    yt = YouTube(video_url, use_po_token=True, on_progress_callback = on_progress)
    ys = yt.streams.get_lowest_resolution()
    ys.download(output_path=output_path, filename=video_filename)

video_link = 'https://www.youtube.com/watch?v=qoTa_vfO8-4'

download_youtube_video(video_link, path, f'yourname.mp4', on_progress)

🎯 Expected Behavior

Describe what you expected to happen instead of the observed behaviour.

What would be expected is that this video is downloaded, like was done before. Only today this error started occuring.


📸 Screenshots or Logs

Error:

Traceback (most recent call last):
  File "/my/path/my_python_file.py", line 266, in <module>
    download_youtube_video(video_link, LOCAL_VIDEOS_PATH, f'{video_id}.mp4', on_progress)
  File "/my/path/download_utils.py", line 159, in download_youtube_video
    ys = yt.streams.get_lowest_resolution()
  File "/my/path/python3.8/site-packages/pytubefix/__main__.py", line 649, in streams
    self.check_availability()
  File "/my/path/.local/lib/python3.8/site-packages/pytubefix/__main__.py", line 316, in check_availability
    status, messages = extract.playability_status(self.vid_info)
  File "/my/path/.local/lib/python3.8/site-packages/pytubefix/extract.py", line 106, in playability_status
    status_dict = player_response.get('playabilityStatus', {})
AttributeError: 'NoneType' object has no attribute 'get'

🖥️ Environment Details

Fill in the details below about your setup:

  • Ubuntu linux
  • Python 3.8.10
  • Pytubefix 8.9.0

📋 Additional Context

Add any additional information or context that might help us resolve the issue.


🚀 Next Steps

Once submitted, we will triage the issue. Make sure to respond to follow-up questions to keep the process smooth.

@FreekCool FreekCool added the bug Something isn't working label Jan 2, 2025
@bigbear22941
Copy link

bigbear22941 commented Jan 5, 2025

here the same...

File "C:\Python37\Lib\site-packages\pytubefix_main_.py", line 775, in length
return int(self.vid_info.get('videoDetails', {}).get('lengthSeconds'))
^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get'

@NannoSilver
Copy link
Contributor

I started to get the same error after upgraded Pytubefix from 8.8.1 to 8.10.

Potentially is an issue related to the way the Exceptions are handled in latest versions of pytubefix.
All the error cases I looked at were about videos not available in my region or not available at all.

For example:
The video https://www.youtube.com/watch?v=VicRV0Y187Q
Opening the video in the browser leads to This live stream recording is not available. error.

image

Using pytubefix 8.8.1 raises the error VicRV0Y187Q does not have a live stream recording available
Using pytubefix 8.10 raises the error 'NoneType' object has no attribute 'get'

The problem was fixed by downgrading pytubefix to version 8.8.1

@felipeucelli
Copy link
Contributor

@NannoSilver

You are right, the update that implemented fallback #397 clients was causing this error for videos that return UNPLAYABLE

I sent an update that fixes this, would you mind testing it #402

@NannoSilver
Copy link
Contributor

NannoSilver commented Jan 6, 2025

@NannoSilver

You are right, the update that implemented fallback #397 clients was causing this error for videos that return UNPLAYABLE

I sent an update that fixes this, would you mind testing it #402

I am running pytubefix 8.10 with the #402 patch in my production server at a couple of hours and seems the issue is fixed.
Thank you!

@NannoSilver
Copy link
Contributor

@felipeucelli
There are a few cases that still are generating the 'NoneType' object has no attribute 'get' error on pytubefix 8.10.1 (that incorporates #402).

Here is a list of videos generating such error spotted in my server so far:

https://www.youtube.com/watch?v=uov4sLUnh7Q
https://www.youtube.com/watch?v=PcBplNzHCmQ
https://www.youtube.com/watch?v=6oyMqGt0m3w
https://www.youtube.com/watch?v=N8eINkHAbH0
https://www.youtube.com/watch?v=RCRZrzyUz3s
https://www.youtube.com/watch?v=1IQT8HFwCBo
https://www.youtube.com/watch?v=UvQ6PxXPDxo

Opening with the browser, all of them have the Video unavailable status.

@felipeucelli
Copy link
Contributor

@NannoSilver

Try this patch and tell us the result #403

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: waiting
Development

No branches or pull requests

4 participants