如何解决 PyTube 中的 HTTP 错误 400:错误请求?

问题描述 投票:0回答:1

我用 pyTube 库做了一个简单的 3 行项目。它所做的只是从 YT 下载视频。我通常用它下载100分钟左右的手球比赛视频。 7 天前我上次使用它时一切正常,但现在它抛出“HTTP 错误 400:错误请求”错误。

from pytube import YouTube

youtubeObject = YouTube('https://www.youtube.com/watch?v=DASMWPUFFP4')

youtubeObject = youtubeObject.streams.get_highest_resolution()

youtubeObject.download('D:\\Utakmice')

它适用于较短的视频,但不适用于任何其他类似长度(约 100 分钟)的视频。我尝试升级 pyTube 库并清理浏览器缓存,但没有帮助。试图将北斗七星挖掘到urllib,但也找不到任何东西。我收到的错误是:

urllib.error.HTTPError:HTTP 错误 400:错误请求

在网上找不到任何解决方案,因此感谢任何帮助。预先感谢。

python http-error pytube
1个回答
0
投票

得到了同样的错误,因为看起来发送到 YouTube 服务器的请求不是一个好的请求。

回溯(最近一次调用最后一次):

    File "/var/www/html/ytd_web_app/venv/lib/python3.10/site-packages/flask/app.py", line 2213, in __call__
    return self.wsgi_app(environ, start_response)
    File "/var/www/html/ytd_web_app/venv/lib/python3.10/site-packages/flask/app.py", line 2193, in wsgi_app
    response = self.handle_exception(e)
    File "/var/www/html/ytd_web_app/venv/lib/python3.10/site-packages/flask/app.py", line 2190, in wsgi_app
    response = self.full_dispatch_request()
    File "/var/www/html/ytd_web_app/venv/lib/python3.10/site-packages/flask/app.py", line 1486, in full_dispatch_request
    rv = self.handle_user_exception(e)
    File "/var/www/html/ytd_web_app/venv/lib/python3.10/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
    File "/var/www/html/ytd_web_app/venv/lib/python3.10/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
    File "/var/www/html/ytd_web_app/Routes/Media.py", line 90, in getMedia
    file = getMetaData(file_name)
    File "/var/www/html/ytd_web_app/Routes/Media.py", line 43, in getMetaData
    response = json.dumps(media.verifyPlatform(), indent=4)
    File "/var/www/html/ytd_web_app/Models/Media.py", line 164, in verifyPlatform
    "data": self.handleYouTube()
    File "/var/www/html/ytd_web_app/Models/Media.py", line 227, in handleYouTube
    youtube = self._YouTubeDownloader.search()
    File "/var/www/html/ytd_web_app/Models/YouTubeDownloader.py", line 297, in search
    "author_channel": self.getVideo().channel_url,
    File "/var/www/html/ytd_web_app/venv/lib/python3.10/site-packages/pytube/__main__.py", line 432, in channel_url
    return f'https://www.youtube.com/channel/{self.channel_id}'
    File "/var/www/html/ytd_web_app/venv/lib/python3.10/site-packages/pytube/__main__.py", line 424, in channel_id
    return self.vid_info.get('videoDetails', {}).get('channelId', None)
    File "/var/www/html/ytd_web_app/venv/lib/python3.10/site-packages/pytube/__main__.py", line 246, in vid_info
    innertube_response = innertube.player(self.video_id)
    File "/var/www/html/ytd_web_app/venv/lib/python3.10/site-packages/pytube/innertube.py", line 448, in player
    return self._call_api(endpoint, query, self.base_data)
    File "/var/www/html/ytd_web_app/venv/lib/python3.10/site-packages/pytube/innertube.py", line 390, in _call_api
    response = request._execute_request(
    File "/var/www/html/ytd_web_app/venv/lib/python3.10/site-packages/pytube/request.py", line 37, in _execute_request
    return urlopen(request, timeout=timeout)  # nosec
    File "/usr/lib/python3.10/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
    File "/usr/lib/python3.10/urllib/request.py", line 525, in open
    response = meth(req, response)
    File "/usr/lib/python3.10/urllib/request.py", line 634, in http_response
    response = self.parent.error(
    File "/usr/lib/python3.10/urllib/request.py", line 563, in error
    return self._call_chain(*args)
    File "/usr/lib/python3.10/urllib/request.py", line 496, in _call_chain
    result = func(*args)
    File "/usr/lib/python3.10/urllib/request.py", line 643, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
    urllib.error.HTTPError: HTTP Error 400: Bad Request
© www.soinside.com 2019 - 2024. All rights reserved.