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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

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

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

蝴蝶不菲 2023-12-29 10:27:57
當(dāng)嘗試運(yùn)行我的小型測(cè)試腳本時(shí),Pytube 十分之五會(huì)向我發(fā)送此錯(cuò)誤。這是腳本: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 但我似乎無(wú)法解決這個(gè)問(wèn)題。越來(lái)越令人困惑的是,該腳本一半的時(shí)間有效,但另一半則無(wú)效。
查看完整描述

6 回答

?
慕斯王

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超2個(gè)贊

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

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

如果其他人遇到此錯(cuò)誤或問(wèn)題,請(qǐng)?jiān)诮K端或 cmd 中運(yùn)行此命令: python -m pip install git+https://github.com/nficano/pytube

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


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

TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超11個(gè)贊

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


#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

錯(cuò)誤:


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

KeyError: 'assets'

之所以給出這個(gè)源代碼片段,是因?yàn)樵撛创a片段不支持字典搜索,因此出現(xiàn) 'KeyError' 鍵錯(cuò)誤,因?yàn)?'assets' 不是有效鍵,并且源代碼不是字典。所以我做了這個(gè)腳本,我相信它取代了原來(lái)的腳本,但在我的腳本中,特別是出現(xiàn)了其他錯(cuò)誤。


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ù)想要的字符串形式,而不是字典形式。


我希望我為未來(lái)更完整的解決方案做出了貢獻(xiàn):)


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

TA貢獻(xiàn)1852條經(jīng)驗(yàn) 獲得超7個(gè)贊

將此函數(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


查看完整回答
反對(duì) 回復(fù) 2023-12-29
?
繁華開(kāi)滿天機(jī)

TA貢獻(xiàn)1816條經(jīng)驗(yàn) 獲得超4個(gè)贊

看來(lái) Pytube 模塊已更新。

它適用于 pytube 包

即嘗試pip install pytube卸載 pytube 變體


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

TA貢獻(xiàn)2036條經(jīng)驗(yàn) 獲得超8個(gè)贊

我遇到了同樣的問(wèn)題,更新 pytube到當(dāng)前可用的最新版本問(wèn)題消失了。

pip install pytube==10.0.0

或者

pip install --upgrade pytube


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

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超10個(gè)贊

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

編輯:從評(píng)論中,如果這些都不起作用,請(qǐng)嘗試pytube4

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


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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

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