第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Pytube 僅定期工作(KeyError:'assets')

Pytube 僅定期工作(KeyError:'assets')

蝴蝶不菲 2023-12-29 10:27:57
當嘗試運行我的小型測試腳本時,Pytube 十分之五會向我發(fā)送此錯誤。這是腳本:import pytubeimport urllib.requestfrom pytube import YouTubeyt = YouTube('https://www.youtube.com/watch?v=3NCyD3XoJgM')print('Youtube video title is: ' + yt.title + '! Downloading now!')這是我得到的:Traceback (most recent call last):  File "youtube.py", line 6, in <module>    yt = YouTube('https://www.youtube.com/watch?v=3NCyD3XoJgM')  File "C:\Users\test\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pytube\__main__.py", line 91, in __init__    self.prefetch()  File "C:\Users\test\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pytube\__main__.py", line 183, in prefetch    self.js_url = extract.js_url(self.watch_html)  File "C:\Users\test\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pytube\extract.py", line 143, in js_url    base_js = get_ytplayer_config(html)["assets"]["js"]KeyError: 'assets'我很困擾。我嘗試重新安裝 Python 加 pytube 但我似乎無法解決這個問題。越來越令人困惑的是,該腳本一半的時間有效,但另一半則無效。
查看完整描述

6 回答

?
慕斯王

TA貢獻1864條經(jīng)驗 獲得超2個贊

現(xiàn)在已經(jīng)100%修復(fù)了:

https://github.com/nficano/pytube/pull/767#issuecomment-716184994

如果其他人遇到此錯誤或問題,請在終端或 cmd 中運行此命令: python -m pip install git+https://github.com/nficano/pytube

尚未隨 pip 安裝一起發(fā)布的 pytubeX 更新。GitHub 鏈接是當前開發(fā)人員對情況的解釋。


查看完整回答
反對 回復(fù) 2023-12-29
?
回首憶惘然

TA貢獻1847條經(jīng)驗 獲得超11個贊

我也遇到了同樣的麻煩,但我保證最上面的答案不能解決任何問題,只是隱藏問題,直到它再次出現(xiàn)。我調(diào)查了“extract.py”文件的范圍,發(fā)現(xiàn)了一個錯誤。該范圍通過字典搜索在視頻所在的 Youtube 頁面的源代碼中搜索“字符串”片段,例如:


#Example ---------------

Vars = {

    'name':'luis'

    'age':'27'

}

print(Vars['name'])


result: 'luis'


#Extract.py Code -------


def js_url(html: str) -> str:

"""Get the base JavaScript url.


Construct the base JavaScript url, which contains 

the decipher

"transforms".


:param str html:

    The html contents of the watch page.

"""

base_js = get_ytplayer_config(html)["assets"]["js"]

return "https://youtube.com" + base_js

錯誤:


base_js = get_ytplayer_config(html)["assets"]["js"]

KeyError: 'assets'

之所以給出這個源代碼片段,是因為該源代碼片段不支持字典搜索,因此出現(xiàn) 'KeyError' 鍵錯誤,因為 'assets' 不是有效鍵,并且源代碼不是字典。所以我做了這個腳本,我相信它取代了原來的腳本,但在我的腳本中,特別是出現(xiàn)了其他錯誤。


def js_url(html: str) -> str:

"""Get the base JavaScript url.


Construct the base JavaScript url, which contains 

the decipher

"transforms".


:param str html:

    The html contents of the watch page.

"""

base_js = html[html.find('js') + 4:html.find('.js') 

+ 4]

return "https://youtube.com" + base_js

上面的腳本搜索函數(shù)想要的字符串形式,而不是字典形式。


我希望我為未來更完整的解決方案做出了貢獻:)


查看完整回答
反對 回復(fù) 2023-12-29
?
慕姐4208626

TA貢獻1852條經(jīng)驗 獲得超7個贊

將此函數(shù)添加到 extract.py


def get_ytplayer_js(html: str) -> Any:

    """Get the YouTube player base JavaScript path.


    :param str html

    The html contents of the watch page.

    :rtype: str

    :returns:

    Path to YouTube's base.js file.

    """

    js_url_patterns = [

        r"\"jsUrl\":\"([^\"]*)\"",

    ]

    for pattern in js_url_patterns:

        regex = re.compile(pattern)

        function_match = regex.search(html)

        if function_match:

            logger.debug("finished regex search, matched: %s", pattern)

            yt_player_js = function_match.group(1)

            return yt_player_js


    raise RegexMatchError(

       caller="get_ytplayer_js", pattern="js_url_patterns"

    )

并將 extract.py 中的函數(shù)“js_url”更改為:


def js_url(html: str) -> str:

    """Get the base JavaScript url.


    Construct the base JavaScript url, which contains the decipher

    "transforms".


    :param str html:

        The html contents of the watch page.

    """

    base_js = get_ytplayer_config(html)["assets"]["js"]

    return "https://youtube.com" + base_js

到:


def js_url(html: str) -> str:

    """Get the base JavaScript url.


    Construct the base JavaScript url, which contains the decipher

    "transforms".


    :param str html:

        The html contents of the watch page.

    """

    base_js = get_ytplayer_js(html)

    return "https://youtube.com" + base_js


查看完整回答
反對 回復(fù) 2023-12-29
?
繁華開滿天機

TA貢獻1816條經(jīng)驗 獲得超4個贊

看來 Pytube 模塊已更新。

它適用于 pytube 包

即嘗試pip install pytube卸載 pytube 變體


查看完整回答
反對 回復(fù) 2023-12-29
?
慕桂英3389331

TA貢獻2036條經(jīng)驗 獲得超8個贊

我遇到了同樣的問題,更新 pytube到當前可用的最新版本問題消失了。

pip install pytube==10.0.0

或者

pip install --upgrade pytube


查看完整回答
反對 回復(fù) 2023-12-29
?
慕桂英546537

TA貢獻1848條經(jīng)驗 獲得超10個贊

如果您正在使用該軟件包pytubepytube3,我建議您卸載它并安裝pytubeX。無需更改導(dǎo)入。我發(fā)現(xiàn)它的工作更加可靠。

編輯:從評論中,如果這些都不起作用,請嘗試pytube4

編輯:pytube現(xiàn)在再次維護!


查看完整回答
反對 回復(fù) 2023-12-29
  • 6 回答
  • 0 關(guān)注
  • 279 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號