Python Library Query Question

196 views
Skip to first unread message

Drew Lauck

unread,
Jan 7, 2020, 9:19:29 AM1/7/20
to AdWords API and Google Ads API Forum
Good morning,

Currently using the python client library (https://github.com/googleads/google-ads-python) and running the get_keyword_stats.py (https://github.com/googleads/google-ads-python/blob/master/examples/reporting/get_keyword_stats.py). I've been able to successfully pull data and send it to a remote database when using this query provided in the Github repo:

query = ('SELECT campaign.idcampaign.namead_group.idad_group.name, '
             'ad_group_criterion.criterion_id, '
             'ad_group_criterion.keyword.text, '
             'ad_group_criterion.keyword.match_type, '
             'metrics.impressions, metrics.clicks, metrics.cost_micros '
             'FROM keyword_view WHERE segments.date DURING LAST_30_DAYS '
             'AND campaign.advertising_channel_type = \'SEARCH\' '
             'AND ad_group.status = \'ENABLED\' '
             'AND ad_group_criterion.status IN (\'ENABLED\'\'PAUSED\') '
             'ORDER BY metrics.impressions DESC '
            )
 

The data is fine and looks like it's displaying correctly but when I add more data to request in this query:

query = ('SELECT campaign.idcampaign.namead_group.idad_group.name, '
             'ad_group_criterion.criterion_id, '
             'ad_group_criterion.keyword.text, '
             'ad_group_criterion.keyword.match_type, '
             'metrics.impressions, metrics.clicks, metrics.cost_micros, metrics.absolute_top_impression_percentage, metrics.average_cost, metrics.average_cpc, metrics.average_cpm, metrics.engagement_rate' 
             'FROM keyword_view WHERE segments.date DURING LAST_30_DAYS '
             'AND campaign.advertising_channel_type = \'SEARCH\' '
             'AND ad_group.status = \'ENABLED\' '
             'AND ad_group_criterion.status IN (\'ENABLED\'\'PAUSED\') '
             'ORDER BY metrics.impressions DESC '
            )

I get an error provided here:

Traceback (most recent call last):
  File "get_keyword_stats.py", line 57, in main
    for row in response:
  File "C:\Users\Drew Lauck\AppData\Local\Programs\Python\Python38\lib\site-packages\google\api_core\page_iterator.py", line 212, in _items_iter
    for page in self._page_iter(increment=False):
  File "C:\Users\Drew Lauck\AppData\Local\Programs\Python\Python38\lib\site-packages\google\api_core\page_iterator.py", line 243, in _page_iter
    page = self._next_page()
  File "C:\Users\Drew Lauck\AppData\Local\Programs\Python\Python38\lib\site-packages\google\api_core\page_iterator.py", line 534, in _next_page
    response = self._method(self._request)
  File "C:\Users\Drew Lauck\AppData\Local\Programs\Python\Python38\lib\site-packages\google\api_core\gapic_v1\method.py", line 143, in __call__
    return wrapped_func(*args, **kwargs)
  File "C:\Users\Drew Lauck\AppData\Local\Programs\Python\Python38\lib\site-packages\google\api_core\retry.py", line 281, in retry_wrapped_func
    return retry_target(
  File "C:\Users\Drew Lauck\AppData\Local\Programs\Python\Python38\lib\site-packages\google\api_core\retry.py", line 184, in retry_target
    return target()
  File "C:\Users\Drew Lauck\AppData\Local\Programs\Python\Python38\lib\site-packages\google\api_core\timeout.py", line 214, in func_with_timeout
    return func(*args, **kwargs)
  File "C:\Users\Drew Lauck\AppData\Local\Programs\Python\Python38\lib\site-packages\google\api_core\grpc_helpers.py", line 57, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "C:\Users\Drew Lauck\AppData\Local\Programs\Python\Python38\lib\site-packages\grpc\_interceptor.py", line 216, in __call__
    response, ignored_call = self._with_call(
  File "C:\Users\Drew Lauck\AppData\Local\Programs\Python\Python38\lib\site-packages\grpc\_interceptor.py", line 257, in _with_call
    return call.result(), call
  File "C:\Users\Drew Lauck\AppData\Local\Programs\Python\Python38\lib\site-packages\grpc\_interceptor.py", line 126, in result
    raise self._exception
  File "C:\Users\Drew Lauck\AppData\Local\Programs\Python\Python38\lib\site-packages\grpc\_interceptor.py", line 242, in continuation
    response, call = self._thunk(new_method).with_call(
  File "C:\Users\Drew Lauck\AppData\Local\Programs\Python\Python38\lib\site-packages\grpc\_interceptor.py", line 266, in with_call
    return self._with_call(
  File "C:\Users\Drew Lauck\AppData\Local\Programs\Python\Python38\lib\site-packages\grpc\_interceptor.py", line 257, in _with_call
    return call.result(), call
  File "C:\Users\Drew Lauck\AppData\Local\Programs\Python\Python38\lib\site-packages\grpc\_interceptor.py", line 126, in result
    raise self._exception
  File "C:\Users\Drew Lauck\AppData\Local\Programs\Python\Python38\lib\site-packages\grpc\_interceptor.py", line 242, in continuation
    response, call = self._thunk(new_method).with_call(
  File "C:\Users\Drew Lauck\AppData\Local\Programs\Python\Python38\lib\site-packages\grpc\_interceptor.py", line 266, in with_call
    return self._with_call(
  File "C:\Users\Drew Lauck\AppData\Local\Programs\Python\Python38\lib\site-packages\grpc\_interceptor.py", line 255, in _with_call
    call = self._interceptor.intercept_unary_unary(
  File "C:\Users\Drew Lauck\AppData\Local\Programs\Python\Python38\lib\site-packages\google\ads\google_ads\interceptors\exception_interceptor.py", line 139, in intercept_unary_unary
    self._handle_grpc_failure(response)
  File "C:\Users\Drew Lauck\AppData\Local\Programs\Python\Python38\lib\site-packages\google\ads\google_ads\interceptors\exception_interceptor.py", line 105, in _handle_grpc_failure
    google_ads_failure = self._get_google_ads_failure(trailing_metadata)
  File "C:\Users\Drew Lauck\AppData\Local\Programs\Python\Python38\lib\site-packages\google\ads\google_ads\interceptors\exception_interceptor.py", line 68, in _get_google_ads_failure
    ga_failure = error_protos.errors_pb2.GoogleAdsFailure()
AttributeError: module 'google.ads.google_ads.v2.proto.errors' has no attribute 'errors_pb2'


The script is very inconsistent because it's run before with no errors and data was able to be pulled and pushed into MySQL. Is there a limit to the amount of data I can request in a query or is there a limit for requests? I went through the keyword_view report (https://developers.google.com/google-ads/api/fields/v2/keyword_view) and verified all the data I'm requesting can be pulled from this report. If you've run into this problem, know about a workaround or know anything about these specific errors, please let me know!

Lucas Gomide

unread,
Jan 7, 2020, 9:25:39 AM1/7/20
to AdWords API and Google Ads API Forum
I have the same issue, none examples of queries works. 

I saw the code base, and the errors_pb2 module exists only on google_ads.V1. This module does not exists on google_ads.V2.

I'm trying to fix it since yesterday.  There is an issue on Github as well https://github.com/googleads/google-ads-python/issues/200

Lucas Gomide

unread,
Jan 7, 2020, 9:41:13 AM1/7/20
to AdWords API and Google Ads API Forum
Nevermind what a said above. The file does exist

~ I saw the code base, and the errors_pb2 module exists only on google_ads.V1. This module does not exists on google_ads.V2 ~

Google Ads API Forum Advisor Prod

unread,
Jan 7, 2020, 2:50:37 PM1/7/20
to adwor...@googlegroups.com

Hi Drew,

Thanks for reaching out to us. I tried running your query and did not encounter any issues with it. This could be an issue stemming from your set up. Could I ask you to download and install the latest version of our client library for Google Ads Python here, and try running the query again? If you still run into issues, could you please post your issue here, as our client library support team would be best equipped to assist you. If you have any further questions please let me know.

Thank you,
Bryan, Google Ads API Team



ref:_00D1U1174p._5001UOGBKC:ref

Drew Lauck

unread,
Jan 7, 2020, 4:00:00 PM1/7/20
to AdWords API and Google Ads API Forum
Thanks for the reply!

The query works, most likely a setup issue. Do you have any idea what the error I referenced above means? Is it a timeout issue or a setup issue? I'm used to coding in javascript where error messages are somewhat helpful but I can't really decipher what the problem is from the message the script provided. Any additional information would be extremely helpful if I encounter this again.

Google Ads API Forum Advisor Prod

unread,
Jan 8, 2020, 9:55:01 AM1/8/20
to drewl...@gmail.com, adwor...@googlegroups.com

Hi Drew,

It looks like it’s a setup issue in which there could have been a problem with the way the client library was installed, in which it is not reading the attribute file ‘errors_pb2’ while the the attribute is being used in the script. In this case I would recommend you to download and install the latest version of our client library to remedy setup issues. For Google Ads Python, you can find the latest version here. Let me know if you have further questions.

Drew Lauck

unread,
Jan 8, 2020, 9:56:50 AM1/8/20
to AdWords API and Google Ads API Forum
Understood. Thank you for your help.
Reply all
Reply to author
Forward
0 new messages