2

我使用 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)
    ```
4

1 回答 1

1

尝试在 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
    }
于 2022-01-25T11:21:50.557 回答