我使用 ytdl 构建了一个不和谐的机器人,它工作正常,但随机,我收到此错误,我无法找出原因:(我用 ...截断了链接,因为它太长了)
[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)
```