#2157·pytube

HTTP Error 400: Bad Request

Author: stallumCreated Aug 5, 2025Updated Oct 6, 2025
Labelsbug

Describe the bug I think the code was broke to find the new information about vido, somthing like an alteration on sourcee code of youtube

To Reproduce Please provide the following information: - The video or playlist url that is causing the error.

import re import os from pytube import YouTube

class YoutubeDownloader: def baixarVideo(self, link): try: print(f'Baixando vídeo do link: {link}') yt = YouTube(link) titulo = yt.title video = yt.streams.get_highest_resolution()

        output_path = '_videos'
        if not os.path.exists(output_path):
            os.makedirs(output_path)
            print(f'Pasta criada: {output_path}')
        
        title = re.sub(r'[<>:"/\\|?*]', '', titulo)
        title = title.replace("'", "")
        title = title.strip().replace(' ', '_')
        title = f'{title}.mp4'
        video_path = video.download(output_path, title)
        print(f"Baixado vídeo '{titulo}' para '{video_path}'")
        return video_path
    except Exception as e:
        print(f"Erro ao baixar vídeo: {e}")
        return None

if name == 'main': yt = YoutubeDownloader() link = 'https://youtu.be/VmRynpqImic?si=PPFEso3FWf_NMNT6' yt.baixarVideo(link)

Expected behavior This code has to download the video in the created path.

Output Traceback (most recent call last): File "c:\Users\stall\Documents\Obsidian_enhanced_V2\\utils\download_youtube.py", line 30, in yt.baixar_video(link) ~~~~~~~~~~~~~~~^^^^^^ File "c:\Users\stall\Documents\Obsidian_enhanced_V2\\utils\download_youtube.py", line 9, in baixar_video titulo = yt.title ^^^^^^^^ File "C:\Users\stall\Documents\programacao\projetos\VEGA\venv\Lib\site-packages\pytube_main_.py", line 341, in title self.title = self.vid_info['videoDetails']['title'] ^^^^^^^^^^^^^ File "C:\Users\stall\Documents\programacao\projetos\VEGA\venv\Lib\site-packages\pytube_main.py", line 246, in vid_info innertube_response = innertube.player(self.video_id) File "C:\Users\stall\Documents\programacao\projetos\VEGA\venv\Lib\site-packages\pytube\innertube.py", line 448, in player return self._call_api(endpoint, query, self.base_data) ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\stall\Documents\programacao\projetos\VEGA\venv\Lib\site-packages\pytube\innertube.py", line 390, in _call_api response = request._execute_request( endpoint_url, ...<2 lines>... data=data ) File "C:\Users\stall\Documents\programacao\projetos\VEGA\venv\Lib\site-packages\pytube\request.py", line 37, in _execute_request
return urlopen(request, timeout=timeout) # nosec File "C:\Users\stall\AppData\Local\Programs\Python\Python313\Lib\\urllib\request.py", line 189, in urlopen return opener.open(url, data, timeout) ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^ File "C:\Users\stall\AppData\Local\Programs\Python\Python313\Lib\\urllib\request.py", line 495, in open response = meth(req, response) File "C:\Users\stall\AppData\Local\Programs\Python\Python313\Lib\\urllib\request.py", line 604, in http_response response = self.parent.error( 'http', request, response, code, msg, hdrs) File "C:\Users\stall\AppData\Local\Programs\Python\Python313\Lib\\urllib\request.py", line 533, in error return self._call_chain(*args) ~~~~~~~~~~~~~~~~^^^^^^^ File "C:\Users\stall\AppData\Local\Programs\Python\Python313\Lib\\urllib\request.py", line 466, in _call_chain result = func(*args) File "C:\Users\stall\AppData\Local\Programs\Python\Python313\Lib\\urllib\request.py", line 613, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 400: Bad Request

System information Please provide the following information:

  • Python 3.13.5
  • Pytube 15.0.0
  • pip isntall pytube

Aparentelly pytube was discontinued, BUT, has another one "pytubefix" you can also install has the same comands. Be happy.