You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用YouTube Data API v3更新视频描述时遭遇backendError的问题求助

YouTube Data API v3更新视频描述时遭遇backendError的问题求助

大家好,我之前反复运行、甚至部署在AWS定时任务里的代码现在突然报错了,错误类型是backendError,我猜测这和视频描述的内容变化有关,想请各位帮忙排查一下问题。

问题详情

当我执行以下更新视频信息的代码时,会触发后端错误:

request = youtube_client.videos().update(
        part="snippet,status,localizations",
        body={
            "id": VIDEO_ID,
            "localizations": translations,
            "snippet": {
                "categoryId": 22,
                "defaultLanguage": "en",
                "description": video_description, # todo: fix ; back end error occurs here 
                "tags": [
                    "automation",
                    "python",
                    "youtube api"
                ],
                "title": title,
            },
            "status": {
                "privacyStatus": "public"
            },
        }
    )
response = execute_request(request)

其中execute_request函数的实现如下,用于处理请求和错误捕获:

def execute_request(request: HttpRequest) -> dict:
    try:
        response = request.execute()
    except HttpError as err:
        print()

        error_details = err.error_details[0]
        
        print(f"{error_details=}")

        if (error_details and 
            err.__dict__["resp"]["status"]):
            display_error_and_exit(f"HTTP error: {error_details["message"]}")
        else:
            display_error_and_exit(f"An unexpected HTTPError occurred while executing a request: {err}")
    except Exception as err:
        display_error_and_exit(f"An unexpected error occurred while executing a request: {err}")

    return response

运行代码后得到的错误信息是:

{'message': 'Backend Error', 'domain': 'global', 'reason': 'backendError'}

但如果我把snippet里的这一行代码注释掉:

"description": video_description, 

请求就能成功执行,但视频的描述会被清空——这让我很困惑,因为translations里已经包含了英文(en)的本地化描述,按道理应该会生效才对。

当前的视频描述内容

我打印出了当前的video_description内容,具体如下:

video_description ="time: 01/25/2025 16:50:06 UTC\n\nthis channel has 8 subscribers.\n\nthis video was published 21 days ago in UTC.\n\nviews: 57\ncomments: 2\nlikes: 1\nfavorites: 0\n\nthese numbers were retrieved using the Youtube Data V3 API.\n\nthis video's title, description, and translations update approximately every 9 minutes.\nthe thumbnail updates once a day.\n\nthe translations were automated as well using the deepl deep-translator.\ntry switching to one of the following languages: english, spanish, german, french, and japanese."

这个描述是通过以下代码动态生成的:

video_description = f"time: {formatted_now} UTC\n\nthis channel has {subscriber_count} {plural_sub_text}.\n\nthis video was published {time_since_published} days ago in UTC.\n\nviews: {views}\ncomments: {comments}\nlikes: {likes}\nfavorites: {favorites}\n\nthese numbers were retrieved using the Youtube Data V3 API.\n\nthis video's title, description, and translations update approximately every 9 minutes.\nthe thumbnail updates once a day.\n\nthe translations were automated as well using the deepl deep-translator.\ntry switching to one of the following languages: {join_languages()}."

我的猜测

这段代码之前一直运行正常,最近才突然出现这个问题。我怀疑是不是video_description里包含了某些YouTube API不允许的字符,但我搜了一圈也没找到类似的案例。

如果需要更多信息,我随时可以补充,感谢大家的帮助!

备注:内容来源于stack exchange,提问作者Jordan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 15:04:34