运行Google Ads API示例程序时出现问题

问题描述

我正在尝试从https://developers.google.com/google-ads/api/docs/reporting/example#python运行Google-Ads python示例,但是我的代码无法进入try块。 这是我的代码

from googleadspython.google.ads.google_ads.client import GoogleAdsClient
from googleadspython.google.ads.google_ads.errors import GoogleAdsException
# import google.ads.google_ads.client
customer_id = "1438269192"
customer_id_Currency = "3673645567"
print('CUST--',customer_id)
client = GoogleAdsClient.load_from_storage('/home/mayureshkadam/google-ads.yaml')

ga_service = client.get_service('GoogleAdsService',version='v4')
print('---------')
query = ('SELECT campaign.id,campaign.name FROM campaign '
         'ORDER BY campaign.id')

# Issues a search request using streaming.
response = ga_service.search_stream(customer_id,query=query)
print('/////////',response)
try:
    print('In there')
    for batch in response:
        print('RESP',response)
        for row in batch.results:
            print(f'Campaign with ID {row.campaign.id.value} and name '
                  f'"{row.campaign.name.value}" was found.')
except GoogleAdsException as ex:
    print(f'Request with ID "{ex.request_id}" Failed with status '
          f'"{ex.error.code().name}" and includes the following errors:')
    for error in ex.failure.errors:
        print(f'\tError with message "{error.message}".')
        if error.location:
            for field_path_element in error.location.field_path_elements:
                print(f'\t\tOn field: {field_path_element.field_name}')

上面的代码在运行时会运行到try块的(在那里)print语句,但是它没有进入for batch in response:的for循环中,这可能是什么原因?请帮忙。

这是运行程序时打印语句的输出

CUST-- 1438269192
---------
///////// <google.api_core.grpc_helpers._StreamingResponseIterator object at 0x7f03e527b890>
In there
CUST-- 1438269192
---------
///////// <google.api_core.grpc_helpers._StreamingResponseIterator object at 0x7f03e5283850>
In there

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)