python Google Ads API: Troubleshoot Deadline exceeded error 504 for trying to pull geographic region costs for single country for a single day

2,467 views
Skip to first unread message

Nicholas Lynch

unread,
Apr 23, 2019, 3:54:39 AM4/23/19
to AdWords API and Google Ads API Forum

To whom it may concern,

What is the issue in my code or is there a way to extend the deadline/timeout?
I am trying to run a user location report by clicks,cost for Country:USA by states for 1 week. 

When I try to run a geographic view reports for clicks, cost by region by 1 week with the following code I receive a deadline 504 error, but I run the same code for no regions and 1 day it works in 2 seconds. 

See attached python scripts and code below for reference. 


'''SELECT
     segments.geo_target_region,
metrics.clicks,
metrics.cost_micros
FROM
geographic_view
WHERE
customer.id = XXXXXXXXXXX
    AND geographic_view.country_geo_target_constant = 'geoTargetConstants/2840'
AND geographic_view.location_type = 'LOCATION_OF_PRESENCE'
AND segments.week = '2019-04-15'
ORDER BY metrics.clicks DESC
LIMIT
100'''

Even when I try to run the attached code for a week, I still receive a 504 deadline error.

'''SELECT
metrics.clicks,
metrics.cost_micros
FROM
geographic_view
WHERE
customer.id = XXXXXXXXXX
    AND geographic_view.country_geo_target_constant = 'geoTargetConstants/2840'
AND geographic_view.location_type = 'LOCATION_OF_PRESENCE'
AND segments.week = '2019-04-15'
ORDER BY metrics.clicks DESC
LIMIT
100'''



But I can run the following code without issue and it takes 2 seconds.
'''SELECT
metrics.clicks,
metrics.cost_micros
FROM
geographic_view
WHERE
customer.id = XXXXX
    AND geographic_view.country_geo_target_constant = 'geoTargetConstants/2840'
AND geographic_view.location_type = 'LOCATION_OF_PRESENCE'
AND segments.date = '2019-04-15'
ORDER BY metrics.clicks DESC
LIMIT
100'''


python package version: google-ads 1.3.1
geo_report_trouble.py

googleadsapi...@google.com

unread,
Apr 23, 2019, 5:26:13 AM4/23/19
to adwor...@googlegroups.com
Hi Nicholas,

I tried your GAQL queries using my test account and both are working correctly. The Deadline Exceeded error 504 that you are encountering might be due to the volume of data you are retrieving when using the week segment. I would recommend that you break down your report request by adding predicates or by just using the date segment to avoid this error.

Thanks and regards,
Peter
Google Ads API Team

Was your question answered? Please rate your experience with us by taking a short survey.
If not -- reply to this email and tell us what else we can do to help.

Take Survey

Also find us on our blog and discussion group:
http://googleadsdeveloper.blogspot.com/search/label/adwords_api
https://developers.google.com/adwords/api/community/

--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
 
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to adwor...@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups "AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/08697597-a5b9-40e0-8df5-78a6e56a02b3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nicholas Lynch

unread,
Apr 23, 2019, 10:46:36 AM4/23/19
to AdWords API and Google Ads API Forum
The segment.week just specifies the date period from that Monday to Sunday, right?
Is there any issue in how I am parsing that response or is that irrelevant for 504 deadline error?
I can try to predicate by segment.geo_target_region, but what is the best way to pull those values? Because I do not think they are literal string values like 'Florida, United States'. See attachment for desired data I am trying to replicate for automated data pull. 
 
Let me know if you need any additional information

If I try to run the following code that contains predicates, I receive the following error: RequestId: TG0jUIGkLfxwFgMeCKdy2g, IsFault: True, FaultMessage: The following pairs of fields may not be selected together: 'segments.geo_target_region' and 'segments.date' .

def geo_costs(client, customer_id):
    ga_service = client.get_service('GoogleAdsService', version='v1')
    
    query = ('''SELECT
         segments.geo_target_region,
metrics.clicks,
metrics.cost_micros
FROM
geographic_view
WHERE
customer.id = XXXXXXXXXXXX
    AND geographic_view.country_geo_target_constant = 'geoTargetConstants/2840'
AND geographic_view.location_type = 'LOCATION_OF_PRESENCE'
AND segments.date = '2019-04-15'
ORDER BY metrics.clicks DESC
LIMIT
100''')
    
    response = ga_service.search(customer_id, query)
    for row in response:
        print(row.geographic_view.resource_name,",",row.metrics.clicks.value,"," , row.metrics.cost_micros.value)

geo_costs(client,'client_id')


Screen Shot 2019-04-23 at 9.40.37 AM.png

googleadsapi...@google.com

unread,
Apr 23, 2019, 11:36:14 PM4/23/19
to adwor...@googlegroups.com
Hi Nicholas,

Yes, when using the week segment, the input should be the date of the Monday of the week you wish to retrieve and runs the date range until Sunday. Parsing the results does not influence the error you are encountering, it is more likely due to the volume of data being retrieved. As for using the geographic_view.country_geo_target_constant as predicate, the value you input can be derived from this documentation of the resource.

Also, you are getting the (RequestId: TG0jUIGkLfxwFgMeCKdy2g, IsFault: True, FaultMessage: The following pairs of fields may not be selected together: 'segments.geo_target_region' and 'segments.date') error because the 2 fields indicated in the error string are not selectable in the same query.

Thanks and regards,
Peter
Google Ads API Team


Was your question answered? Please rate your experience with us by taking a short survey.
If not -- reply to this email and tell us what else we can do to help.

Take Survey

Also find us on our blog and discussion group:
http://googleadsdeveloper.blogspot.com/search/label/adwords_api
https://developers.google.com/adwords/api/community/

Nicholas Lynch

unread,
Apr 24, 2019, 10:39:47 AM4/24/19
to AdWords API and Google Ads API Forum

How do you pull a list of segment.geo_target_region for USA physical location?  
    AND geographic_view.country_geo_target_constant = 'geoTargetConstants/2840'
AND geographic_view.location_type = 'LOCATION_OF_PRESENCE'

I am trying to pull all of the geo_target_region  names for the physical locations within the USA, specifically just 9 states where I tried the following code, but still received a deadline error.

_DEFAULT_PAGE_SIZE = 1000

def geo_costs(client, customer_id):
    ga_service = client.get_service('GoogleAdsService', version='v1')
    
    query = ('''SELECT
     segments.geo_target_region
FROM
geographic_view
WHERE
customer.id = XXXXXX
    AND geographic_view.country_geo_target_constant = 'geoTargetConstants/2840'
AND geographic_view.location_type = 'LOCATION_OF_PRESENCE'
LIMIT
100''')
    
    
    response = ga_service.search(customer_id, query)
    for row in response:
        print(row.segments.geo_target_region.resource_name)

geo_costs(client,customer_id)


googleadsapi...@google.com

unread,
Apr 25, 2019, 2:44:11 AM4/25/19
to adwor...@googlegroups.com
Hi Nicholas,

Your query appears to be correct as I tried it locally using my test account. The deadline error might indeed be due to a the volume of data you are extracting. However, to have a closer look at the issue as to why you are getting the deadline error, could you provide your clientCustomerId? Also, could you confirm as well how many reports you have already generated when you started encountering the said error?

You may reply to me via the Reply privately to author option.

Thanks and regards,
Peter
Google Ads API Team
Reply all
Reply to author
Forward
0 new messages