urllib2 - 使用 Pytube : signature = cipher. get_signature(js, stream ['s' ]) 出现错误 KeyError: 's'

标签 urllib2 pytube

运行我的 Pytube 脚本时出现此错误:

     signature = cipher.get_signature(js, stream['s'])
     KeyError: 's'

我的代码是这样的:
    url = 'https://www.youtube.com/watch?v='
    train_List = []
    i = 0
    while i < len(my_list):
        if len(my_list[i]) > 6:
            urls = url + my_list[i]
            train_List.append(urls)
            yt=YouTube(train_List[i])
            t=yt.streams.filter(only_audio=True).all()
            t[0].download('/pathtofolder')
            i+=1

我也试过:
    t=yt.streams.filter(file_extension='mp4').all()

我根据此处的建议更改了 cipher.py 和 helper.py 文件:https://github.com/nficano/pytube/issues/353#issuecomment-455116197

但它并没有解决问题。进行更改后,我收到了上面提到的错误。

接下来,我按照其他一些建议运行了“pip install pytube --upgrade”。下载一些音频文件后仍然收到 KeyError 。

我也在 mixins.py 中实现了这个,每个 github 问题:
    if ('signature=' in url) or ('&sig=' in url) or ('&lsig=' in url):

但现在它在 3 次上传后挂起。

有没有人解决这个问题?

最佳答案

我通过将 mixins.py 中的第 49 行更改为以下内容来解决此问题(至少对我而言):

signature = cipher.get_signature(js, stream['url'])

代替
signature = cipher.get_signature(js, stream['s'])

然后将第 55-63 行更改为
logger.debug(
    'finished descrambling signature for itag=%s\n%s',
    stream['itag'], pprint.pformat(
        {
            'url': stream['url'],
            'signature': signature,
        }, indent=2,
    ),
)

关于urllib2 - 使用 Pytube : signature = cipher. get_signature(js, stream ['s' ]) 出现错误 KeyError: 's',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56382295/

相关文章:

javascript - 使用python检索动态网站的源(绕过onclick)

python - Pypi 中缺少 Urllb2 包

python - 从登录的另一端下载文件

python - 我正在尝试使用 pytube 下载视频但是由于某种原因没有下载声音

python - pytube.exceptions.RegexMatchError : get_throttling_function_name: could not find match for multiple in pytube version 12. 0.0

python - 下载视频时pytube错误: urllib.错误。HTTPError:HTTP错误404:未找到

python - 为什么 urllib2.urlopen 打不开 "http://localhost/new-post#comment-29"这样的页面?

python-3.x - 使用 pytube 下载 mp3 格式的视频

Python Pytube 播放列表下载进度

python - urllib2 HTTPError : HTTP Error 414: Request-URI Too Large