首页 > 解决方案 > Google Ads API v8 中不存在指定类型“google_ads_failure”

问题描述

我有两个问题:

我正在调用 G-Ads API 来批量删除广告(代码

for error_detail in error_details:
            # Retrieve an instance of the google_ads_failure class from the client
            failure_message = gAdsServiceWrapper.client.get_type("google_ads_failure")
            # Parse the string into a google_ads_failure message instance.
            # To access class-only methods on the message we retrieve its type.
            google_ads_failure = type(failure_message)
            failure_object = google_ads_failure.deserialize(error_detail.value)

            for error in failure_object.errors:
                # Construct and print a string that details which element in
                # the above ad_group_operations list failed (by index number)
                # as well as the error message and error code.
                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})
  1. 我收到部分错误
  2. 并且代码解析失败(取自官

我的终端显示:

发生部分故障。详情将在下面显示。

Traceback (most recent call last):
  File "D:\projects\bowling\venv\lib\site-packages\google\ads\googleads\client.py", line 426, in get_type
    message_class = getattr(type_classes, name)
  File "D:\projects\bowling\venv\lib\site-packages\google\ads\googleads\v8\__init__.py", line 1753, in __getattr__
    raise AttributeError(f"unknown type {name!r}.")
AttributeError: unknown type 'google_ads_failure'.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\projects\bowling\src\main.py", line 535, in <module>
    main(args.top_id)
  File "D:\projects\bowling\src\main.py", line 141, in main
    removed_ads_count = remove_disapproved_ads_for_account(account)
  File "D:\projects\bowling\src\main.py", line 206, in remove_disapproved_ads_for_account
    remove_ads(ad_removal_operations, ads_to_remove_json, account_id)
  File "D:\projects\bowling\src\main.py", line 300, in remove_ads
    index_array, error_array = _print_results(response_chunk)
  File "D:\projects\bowling\src\main.py", line 439, in _print_results
    failure_message = gAdsServiceWrapper.client.get_type("google_ads_failure")
  File "D:\projects\bowling\venv\lib\site-packages\google\ads\googleads\client.py", line 428, in get_type
    raise ValueError(
ValueError: Specified type 'google_ads_failure' does not exist in Google Ads API v8

标签: pythongoogle-apigoogle-ads-apigoogle-api-python-client

解决方案


failure_message = gAdsServiceWrapper.client.get_type("google_ads_failure")

我认为这应该是 - failure_message = gAdsServiceWrapper.client.get_type("GoogleAdsFailure")


推荐阅读