gpt4 book ai didi

discord.py - 我经常收到 HTTP 错误 403 Forbidden using discord.py and ytdl

转载 作者:行者123 更新时间:2023-12-05 04:36:42 25 4
gpt4 key购买 nike

我使用 ytdl 构建了一个 discord bot,它工作正常但随机出现此错误,我无法找出原因:(我用 ... 截断了链接,因为它太长了)

[https @ 000001ead63ee980] HTTP error 403 Forbidden
https://rr2---sn-uxaxpu5ap5-jp5l.googlevideo.com/videoplayback?expire=...: Server returned 403 Forbidden (access denied)

我认为问题出在这部分代码上:

with youtube_dl.YoutubeDL(ytdlopts) as ydl:
ydl.cache.remove()
info = ydl.extract_info(search_query, download=False)

所以我把它放在 try/catch 中,但它没有捕获到错误。我也试过:

    ydl.cache.remove()

但问题仍然存在,如果问题不在我的代码中,而是在服务器端,那么有没有办法修复或缓解问题?

这些是我的 ffmpeg/ytdl 选项:

    ytdlopts = {
'format': 'bestaudio/best',
'outtmpl': 'downloads/%(extractor)s-%(id)s-%(title)s.%(ext)s',
'restrictfilenames': True,
'nocheckcertificate': True,
'ignoreerrors': False,
'logtostderr': False,
'quiet': True,
'extract_flat': True,
'skip_download': True,
'default_search': 'auto',
'source_address': '0.0.0.0' # ipv6 addresses cause issues sometimes
}

ffmpegopts = {'before_options': '-nostdin','options': '-vn'}
opts = {'extract_flat': True, 'skip_download': True}
ytdl = YoutubeDL(ytdlopts)
```

最佳答案

尝试在 ytdlopts 中执行 ipv4: True 和 'cachedir': False,这样做,你强制执行 ipv4 并清除缓存,我不确定它是否有效,但对我来说工作正常。

ytdlopts = {
'format': 'bestaudio/best',
'outtmpl': 'downloads/%(extractor)s-%(id)s-%(title)s.%(ext)s',
'restrictfilenames': True,
'nocheckcertificate': True,
'ignoreerrors': False,
'logtostderr': False,
'quiet': True,
'extract_flat': True,
'skip_download': True,
'default_search': 'auto',
'source_address': '0.0.0.0' # ipv6 addresses cause issues sometimes
'force-ipv4': True,
'cachedir': False
}

关于discord.py - 我经常收到 HTTP 错误 403 Forbidden using discord.py and ytdl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70776710/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com