npm:youtube-dl 和 Lambda HTTP 错误 429:请求过多

npm:youtube-dl and Lamda HTTP Error 429: Too Many Requests

我正在 运行通过 Lambda 函数安装一个 npm 包:youtube-dl,因为我想创建一个在线转换器。

突然开始运行出现如下错误信息:

{
"errorMessage": "Command failed: /var/task/node_modules/youtube-dl/bin/youtube-dl --dump-json --format=best[ext=mp4] https://www.youtube.com/watch?v=MfTbHITdhEI\nERROR: Unable to download webpage: HTTP Error 429: Too Many Requests (caused by HTTPError()); please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; type  youtube-dl -U  to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.\n",
"errorType": "Error",
"stackTrace": ["ERROR: Unable to download webpage: HTTP Error 429: Too Many Requests (caused by HTTPError()); please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; type  youtube-dl -U  to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.", "", "ChildProcess.exithandler (child_process.js:275:12)", "emitTwo (events.js:126:13)", "ChildProcess.emit (events.js:214:7)", "maybeClose (internal/child_process.js:925:16)", "Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)"]
}

编辑:我前几天测试时 运行 几次,但今天我只 运行 一次。

我认为我的 Lambda 函数使用的 IP 地址现在已被列入黑名单。我不确定如何进行,因为我是一名大三学生,而且对这一切都很陌生。

有办法解决吗?我可以获得新的 IP 地址吗?这会非常昂贵吗?

好的,所以我找到了这个回复:

I am wondering if it's possible that our because our volume is low we just always end up using the same container hence the same IP address?

是的,正是这个原因。只有在没有容器可用时才会生成容器。在 分钟 没有进一步需求后,excess/unneeded 个容器被销毁。

If so is there any way to prevent this?

不,此行为是设计使然。

解决方案:

我注销了 20 分钟,然后返回该功能并再次 运行。成功了

您应该做的是通过重试被限制的请求来处理该错误。

youtube-dl 缺少延迟(每次请求限制)选项。

(请参阅我 post 底部的建议)。

切勿使用 youtube-dl 下载超过一个视频。

您可以搜索 youtube-dl 作者联系方式(电子邮件等)并直接将其写下来,也可以在 github 页面上作为未解决的问题。随着更多的要求,他们会尽可能快地修复它。 目前他们在 gitlab 中对这个问题有很多相同的要求,但他们很难阻止讨论并关闭这个问题的门票。 我认为这是某种不当行为。

我还发现开发人员建议使用代理而不是在他的代码中引入延迟选项 - 非常有趣。 好的,重新使用代理 - 但是这实际上并没有解决问题,因为它缺乏程序设计,无论你是否使用代理,YouTube 限制仍然存在。

请注意: 这不仅会导致主题错误,还会导致 YouTube 阻止您的 IP。 一旦遇到这种情况,即使请求量很小,YouTube 也会一次又一次地阻止您的 IP 可疑。这会导致巨大的问题,因为 IP 被标记为可疑。

没有限制每次请求选项(默认安全值)我认为 youtube-dl 作为 危险软件 应该会引起问题在引入此选项之前我停止使用它。

  1. 建议:

当 youtube-dl 收集许多视频的摘要时使用 Ctrl+S(暂停),Ctrl+Q(恢复)(当您已经下载了频道的许多视频但新视频仍然存在时)。我在吃完 10 点后暂停几分钟。

并使用 --limit-rate 150K(或尽可能低),这可能会帮助您避免达到限制,因为整个传输已成形。

在命令中使用 --force-ipv4 选项。

youTube-dl --force-ipv4 ...

不是我的解决方案,我花了一段时间才理解他的意思(阅读是一门艺术)。它对我有用。
(参见:https://askubuntu.com/questions/1220266/youtube-dl-do-not-working-http-error-429-too-many-requests-how-can-i-solve-this
您必须将选项 --cookies 与 current/correct cookie 文件结合使用。
这是我遵循的步骤
1. 如果您使用 Firefox,请安装插件 cookies.txt,启用插件
2.清除浏览器缓存,清除浏览器cookies(隐私原因)
3. 转到 google.com,然后使用您的 google 帐户
登录 4. 转到 youtube.com
5. 单击 cookies.txt 插件,导出 cookie,将其另存为 cookies.txt(在您要前往 运行 youtube-dl 的同一目录中)
6. 这对我有用 ... youtube-dl --cookies cookies.txt https://www.youtube.com/watch?v=.....
希望对你有帮助。