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

The int() function raises a TypeError when the views attribute in the YouTube class from pytubefix is None #436

Open
Ixiko opened this issue Feb 4, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@Ixiko
Copy link

Ixiko commented Feb 4, 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.

The int() function raises a TypeError when the views attribute in the YouTube class from pytubefix is None. This happens despite the attribute being present, as sometimes YouTube's videoDetails API returns None for the viewCount field.

TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

🔢 Code Snippet

Include the minimal code snippet that reproduces the issue.

from pytubefix import YouTube

yt = YouTube('https://www.youtube.com/watch?v=example')
try:
    views = int(yt.views)  # The error occurs here if yt.views is None
except TypeError as e:
    print(f"TypeError: {e}")

🎯 Expected Behavior

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

The views attribute should either provide a default value (e.g., 0) or handle cases where the value is None. Ideally, the library should ensure that views is always compatible with the int() function to prevent such errors.


📸 Screenshots or Logs

TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

🖥️ Environment Details

Fill in the details below about your setup:

  • Operating System: Windows 11
  • Python Version: 3.11.9
  • Pytubefix Version: 8.12.1

📋 Additional Context

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

This issue might be due to inadequate validation of the videoDetails API response. Specifically, when the viewCount field is missing or set to None, it causes the error. A potential solution would be to add a fallback value (e.g., 0) to the views property in the pytubefix library.


🚀 Next Steps

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

This report contains all necessary information to reproduce the issue. Please let me know if further details are required. Thank you for your support!

@drmanche
Copy link

A possible solution in the library is this:

view_count = self.vid_info.get("videoDetails", {}).get("viewCount")
return int(view_count) if view_count is not None else 0

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

2 participants