pytube Trouble Shooting

2024. 7. 18. 00:12파이썬

urllib.error.HTTPError: HTTP Error 400: Bad Request

참조: https://github.com/pytube/pytube/issues/1894

 

[BUG] Age restriction fix is no longer working, producing 400, bad request · Issue #1894 · pytube/pytube

Describe the bug When you use the age restriction fix that has always worked (described here), it now produces bad request. To Reproduce Please provide the following information: innterube.py steps...

github.com

프로그램 상단에 아래 내용을 포함해줘서 해결함

from pytube.innertube import _default_clients

_default_clients["ANDROID"]["context"]["client"]["clientVersion"] = "19.08.35"
_default_clients["IOS"]["context"]["client"]["clientVersion"] = "19.08.35"
_default_clients["ANDROID_EMBED"]["context"]["client"]["clientVersion"] = "19.08.35"
_default_clients["IOS_EMBED"]["context"]["client"]["clientVersion"] = "19.08.35"
_default_clients["IOS_MUSIC"]["context"]["client"]["clientVersion"] = "6.41"
_default_clients["ANDROID_MUSIC"] = _default_clients["ANDROID_CREATOR"]

pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple

참조: https://stackoverflow.com/questions/78727767/regexmatcherror-get-throttling-function-name-could-not-find-match-for-multiple

 

RegexMatchError: get_throttling_function_name: could not find match for multiple v=15.0.0

I cannot use the video download feature via pytube The code I ran yesterday is not working today. How can I fix the error for pytube 15.0.0? def video_indir(video_url, dosya_adi): video = pytube.

stackoverflow.com

 

위 문제를 해결하면, 이 문제가 발생함

get_throttling_function_name를 찾아서 아래 내용 적용

# {설치위치}/.local/lib/python3.10/site-packages/pytube/cipher.py
    function_patterns = [
        # https://github.com/ytdl-org/youtube-dl/issues/29326#issuecomment-865985377
        # https://github.com/yt-dlp/yt-dlp/commit/48416bc4a8f1d5ff07d5977659cb8ece7640dcd8
        # var Bpa = [iha];
        # ...
        # a.C && (b = a.get("n")) && (b = Bpa[0](b), a.set("n", b),
        # Bpa.length || iha("")) }};
        # In the above case, `iha` is the relevant function name
        r'a\.[a-zA-Z]\s*&&\s*\([a-z]\s*=\s*a\.get\("n"\)\)\s*&&.*?\|\|\s*([a-z]+)'
        r'\([a-z]\s*=\s*([a-zA-Z0-9$]+)(\[\d+\])?\([a-z]\)',
        r'\([a-z]\s*=\s*([a-zA-Z0-9$]+)(\[\d+\])\([a-z]\)',
    ]

'파이썬' 카테고리의 다른 글

Python import 하기  (1) 2024.10.19
QR Code 생성  (0) 2024.06.18
mp4 특정 부분 실행하기  (1) 2024.05.06
파이썬 mp4 재생하기  (0) 2024.05.06
Python 사용자 계정 및 홈디렉토리 정보 가져오기  (0) 2021.04.11