Я уже обновил pytube к последней версии с помощью PIP -установки -обновление pytube , но проблема сохраняется. /> Вот самый маленький сценарий, который демонстрирует эту проблему. Он использует только pytube и не имеет других зависимостей. Любой может скопировать и запустить этот код, чтобы увидеть ошибку.
Код: Выделить всё
import logging
from pytube import YouTube
# Configure logging to see the error clearly
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def fetch_video_title(video_id):
"""
Attempts to fetch a single video title using pytube.
This function consistently fails.
"""
video_url = f"https://www.youtube.com/watch?v={video_id}"
logging.info(f"Attempting to fetch title for: {video_url}")
try:
# Create a YouTube object
yt = YouTube(video_url)
# Accessing the .title attribute triggers the network request
title = yt.title
logging.info(f"SUCCESS: Title is '{title}'")
return title
except Exception as e:
# The script always ends up here
logging.error(f"FAILURE for video ID '{video_id}': {e}")
return None
# Main execution block to run the test
if __name__ == "__main__":
# A list of standard YouTube video IDs to test
video_ids_to_test = ["G_Ttz9Dp5lI", "n2f2MPDScdc"]
print("--- Starting Pytube Title Fetch Test ---")
for video_id in video_ids_to_test:
fetch_video_title(video_id)
print("\n--- Test Finished ---")
< /code>
[b] Что я получаю (фактический вывод): < /strong> < /h3>
Когда я запускаю код выше, выход ясно показывает ошибку http 400 < /code> для каждой попытки: < /p>
< /p>
Подробнее здесь: [url]https://stackoverflow.com/questions/79735220/pytube-consistently-fails-with-http-error-400-bad-request-also-on-latest-versio[/url]