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

Google Ads API v8提示google_ads_failure类型不存在如何处理

报错原因
  • 你当前使用的是Google Ads API v8版本,该版本的类型命名规则为大驼峰格式,不存在google_ads_failure这个下划线命名的类型,正确的错误类型名称为GoogleAdsFailure
  • 你参考的代码适配的是v10及以上版本的Google Ads API,更高版本才支持snake_case(小写下划线)格式的类型名调用,和v8不兼容
  • 你收到的partial error属于批量接口的正常返回,代表本次批量操作中部分请求执行失败、部分执行成功,只要正确解析错误信息即可定位失败的请求条目和失败原因
解决方法

直接修改代码中获取错误类型的行即可,调整后的完整错误解析代码如下:

for error_detail in error_details:
    # 适配v8版本的类型名,使用大驼峰格式
    failure_message = gAdsServiceWrapper.client.get_type("GoogleAdsFailure")
    google_ads_failure = type(failure_message)
    failure_object = google_ads_failure.deserialize(error_detail.value)

    for error in failure_object.errors:
        print("A partial failure at index "
              f"{error.location.field_path_elements[0].index} occurred "
              f"\nError message: {error.message}\nError code: "
              f"{error.error_code}")
        index_array.append(error.location.field_path_elements[0].index)
        error_array.append({"error_message": error.message, "error_code": error.error_code})

如果修改后仍有报错,可直接导入v8版本对应的错误类使用:
在代码头部添加导入语句:

from google.ads.googleads.v8.errors.types.google_ads_failure import GoogleAdsFailure

然后把解析部分的代码替换为:

for error_detail in error_details:
    failure_object = GoogleAdsFailure.deserialize(error_detail.value)
    # 后续遍历error的逻辑保持不变

内容的提问来源于stack exchange,提问作者Elad Benda

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.02 00:57:05