首页 > 编程问答 >pytube.exceptions.RegexMatchError:get_throtdling_function_name:找不到多个匹配

pytube.exceptions.RegexMatchError:get_throtdling_function_name:找不到多个匹配

时间:2024-07-28 05:20:19浏览次数:10  
标签:python python-3.x pytube

我曾经通过以下方式下载歌曲:

from pytube import YouTube
video = YouTube('https://www.youtube.com/watch?v=AWXvSBHB210')
video.streams.get_by_itag(251).download()

从今天开始出现此错误:

Traceback (most recent call last):
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 170, in fmt_streams
    extract.apply_signature(stream_manifest, self.vid_info, self.js)
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\extract.py", line 409, in apply_signature
    cipher = Cipher(js=js)
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 43, in __init__
    self.throttling_plan = get_throttling_plan(js)
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 387, in get_throttling_plan
    raw_code = get_throttling_function_code(js)
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 293, in get_throttling_function_code
    name = re.escape(get_throttling_function_name(js))
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 278, in get_throttling_function_name
    raise RegexMatchError(
pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Me\Documents\YouTubeDownloader.py", line 3, in <module>
    video.streams.get_by_itag(251).download()
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 285, in streams
    return StreamQuery(self.fmt_streams)
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 177, in fmt_streams
    extract.apply_signature(stream_manifest, self.vid_info, self.js)
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\extract.py", line 409, in apply_signature
    cipher = Cipher(js=js)
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 43, in __init__
    self.throttling_plan = get_throttling_plan(js)
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 387, in get_throttling_plan
    raw_code = get_throttling_function_code(js)
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 293, in get_throttling_function_code
    name = re.escape(get_throttling_function_name(js))
  File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 278, in get_throttling_function_name
    raise RegexMatchError(
pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple

此錯誤「pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple」表示 PyTube 無法解譯 YouTube 用來提供串流影片的程式碼。這通常發生在 YouTube 變更其程式碼,而 PyTube 還未更新以反映這些變更時。

可以嘗試以下步驟來解決此問題:

1. 更新 PyTube:

確保使用的是最新版本的 PyTube。可以使用 pip 來更新:

bash pip install --upgrade pytube

2. 清除 PyTube 快取:

PyTube 有時會快取 YouTube 頁面的資訊。清除快取可能會解決問題:

python from pytube import YouTube YouTube.clear_cache()

3. 使用不同的 itag 或 streams.filter()

有時特定的 itag 可能會失效。請嘗試使用 streams.filter() 方法來尋找具有所需解析度和檔案類型的其他可用串流:

```python from pytube import YouTube

video = YouTube('https://www.youtube.com/watch?v=AWXvSBHB210') # 尋找音訊串流 stream = video.streams.filter(only_audio=True).first() # 或者尋找特定解析度的影片串流 # stream = video.streams.filter(progressive=True, res="720p").first()

stream.download() ```

4. 等待更新:

如果以上方法都不起作用,則 YouTube 可能進行了重大更改,而 PyTube 開發人員尚未發佈更新。可以在 PyTube GitHub 頁面 上查看是否有任何已知問題或更新。

其他建議:

  • 檢查的網際網路連線。
  • 嘗試重新啟動的 Python 直譯器或電腦。

如果問題仍然存在,可以提供更多上下文資訊,例如 PyTube 版本、作業系統和嘗試下載的影片,以便我可以進一步協助。

标签:python,python-3.x,pytube
From: 68945080

相关文章

  • Python 中的“样板”代码?
    Google有一个Python教程,他们将样板代码描述为“不幸的”,并提供了以下示例:#!/usr/bin/python#importmodulesusedhere--sysisaverystandardoneimportsys#Gatherourcodeinamain()functiondefmain():print'Hellothere',sys.argv[1]#Command......
  • Python 3.9.1 中的 collections.abc.Callable 是否有 bug?
    Python3.9包含PEP585并弃用typing模块中的许多类型,转而支持collections.abc中的类型,现在它们支持__class_getitem__例如Callable就是这种情况。对我来说,typing.Callable和collections.abc.Ca......
  • 列表子类的 Python 类型
    我希望能够定义列表子类的内容必须是什么。该类如下所示。classA(list):def__init__(self):list.__init__(self)我想包含键入内容,以便发生以下情况。importtypingclassA(list:typing.List[str]):#Maybesomethinglikethisdef__init__(self):......
  • Python 中类型友好的委托
    考虑以下代码示例defsum(a:int,b:int):returna+bdefwrap(*args,**kwargs):#delegatetosumreturnsum(*args,**kwargs)该代码运行良好,只是类型提示丢失了。在Python中使用*args,**kwargs来实现​​委托模式是很常见的。如果有一种方法可......
  • 使用 python 支持构建自定义 vim 二进制文件
    背景Debian11vim软件包不包含python3支持。请参阅标题为“Debian11vim中不支持python-证据”的部分下面我需要vim支持python3YouCompleteMevim插件为了构建一个新的,我将vim9.0tarball下载到v......
  • 如何在Python 3.12+中正确使用泛型来提高代码质量?
    我正在尝试使用泛型来改进FastAPI应用程序中的类型注释。我有一个抽象存储库类,在其中使用泛型:fromabcimportABC,abstractmethodfromtypingimportListclassAbstractRepository[T](ABC):@abstractmethodasyncdefadd_one(self,data:dict)->T:......
  • python中的while循环不退出
    我试图完成第一年的python商业课程作业,但我的while循环无法退出,有人能帮忙吗?commisionTable=[{"admin_fee":100,"comm_rate":0.10},{"admin_fee":125,"comm_rate":0.12},{"admin_fee":150,"comm_rate":......
  • python---json文件写入
    ​ 使用到的知识点:os模块执行linux指令、json.dump()、withopenasf代码实现importsysimportosimportjson #向json文件file中添加内容data,其中data的类型为字典defwrite_json(file,data):    #如果文件存在,则删除    if(os.path.exists(fi......
  • python错题记录:布尔运算与逻辑值检测
    一前言环境:python3.10win10二布尔运算与逻辑值检测1案例案例1如上,在布尔运算时,有些时候代码只会运算前面的一部分,剩下的部分根本不会运算。以前在练习算法代码时,就利用这个规则来减少代码的工作量案例2如上,之前好长一段时间,上面的布尔运算总是让我感到困惑布尔运......
  • python---字典遍历
    1、三种常见的字典遍历实现defget_key_value(dics):  '''遍历所有键值对'''  forkey,valueindics.items():    print(f"{key}:{value}")defget_keys(dics):  '''遍历所有的键'''  forkeyindics......