Grabbing KeyWords with Python API Error Please Help

658 views
Skip to first unread message

sarah....@setnow.com

unread,
Aug 25, 2017, 3:25:24 PM8/25/17
to AdWords API Forum
Hi, I have been trying to create a small SEO application using the Google Adwords API in Python 3.6, but I am getting an odd error when I try to run the example program. I can find nothing about this error elsewhere.

My error is:



Your default encoding, cp1252, is not UTF-8. Please run this script with UTF-8 encoding to avoid errors.
<suds.sax.document.Document object at 0x000002546AA344E0>
Response summary - {'requestId': 000557988b89f5280ac113062108357f, 'responseTime': 33, 'serviceName': TargetingIdeaService, 'methodName': get, 'operations': 1, 'isFault': True, 'faultMessage': "[AuthenticationError.CLIENT_CUSTOMER_ID_IS_REQUIRED @ ; trigger:'<null>']"}
Traceback (most recent call last):
  File "C:\Program Files\Anaconda3\lib\site-packages\googleads\util.py", line 123, in PatchedHttpTransportSend
    fp = self.u2open(u2request)
  File "C:\Program Files\Anaconda3\lib\site-packages\suds\transport\http.py", line 132, in u2open
    return url.open(u2request, timeout=tm)
  File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 532, in open
    response = meth(req, response)
  File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 570, in error
    return self._call_chain(*args)
  File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 504, in _call_chain
    result = func(*args)
  File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 500: Internal Server Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Anaconda3\lib\site-packages\suds\client.py", line 613, in send
    reply = self.options.transport.send(request)
  File "C:\Program Files\Anaconda3\lib\site-packages\googleads\util.py", line 134, in PatchedHttpTransportSend
    raise suds.transport.TransportError(e.msg, e.code, e.fp)
suds.transport.TransportError: Internal Server Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/peeps/PycharmProjects/GoogleAdsSEO/SEO.py", line 98, in <module>
    main(adwords_client)
  File "C:/Users/peeps/PycharmProjects/GoogleAdsSEO/SEO.py", line 72, in main
    page = targeting_idea_service.get(selector)
  File "C:\Program Files\Anaconda3\lib\site-packages\googleads\common.py", line 748, in MakeSoapRequest
    self._datetime_packer) for arg in args])
  File "C:\Program Files\Anaconda3\lib\site-packages\suds\client.py", line 521, in __call__
    return client.invoke(args, kwargs)
  File "C:\Program Files\Anaconda3\lib\site-packages\suds\client.py", line 581, in invoke
    result = self.send(soapenv)
  File "C:\Program Files\Anaconda3\lib\site-packages\suds\client.py", line 619, in send
    description=tostr(e), original_soapenv=original_soapenv)
  File "C:\Program Files\Anaconda3\lib\site-packages\suds\client.py", line 670, in process_reply
    raise WebFault(fault, replyroot)
suds.WebFault: Server raised fault: '[AuthenticationError.CLIENT_CUSTOMER_ID_IS_REQUIRED @ ; trigger:'<null>']'

Process finished with exit code 1



My googleads.yaml is configured like this:



adwords:
developer_token: my_dev_token
client_id: my_client_id
client_secret: my_client_secret
refresh_token: my_refresh_token



All I want to do is grab the average monthly searches and competition for a specific keyword, and then a list of related keywords and their average monthly searches and competition. I would appreciate some help with how to go about doing this as well, because I feel that the documentation for amateur developers is a little bit unclear. I believe that this example from the API reference page on Google will get related keywords and something similar to what I'm looking for, but the format of it is a little weird because it was originally written for Python 2.7 and I am and only ever have worked in Python 3.6:



#!/usr/bin/env python
#
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""This example retrieves keywords that are related to a given keyword.
The LoadFromStorage method is pulling credentials and properties from a
"googleads.yaml" file. By default, it looks for this file in your home
directory. For more information, see the "Caching authentication information"
section of our README.
"""

from googleads import adwords


PAGE_SIZE = 100


def main(client):
# Initialize appropriate service.
targeting_idea_service = client.GetService(
'TargetingIdeaService', version='v201708')

# Construct selector object and retrieve related keywords.
offset = 0
selector = {
'searchParameters': [
{
'xsi_type': 'RelatedToQuerySearchParameter',
'queries': ['space cruise']
},
{
# Language setting (optional).
# The ID can be found in the documentation:
# https://developers.google.com/adwords/api/docs/appendix/languagecodes
'xsi_type': 'LanguageSearchParameter',
'languages': [{'id': '1000'}]
},
{
# Network search parameter (optional)
'xsi_type': 'NetworkSearchParameter',
'networkSetting': {
'targetGoogleSearch': True,
'targetSearchNetwork': False,
'targetContentNetwork': False,
'targetPartnerSearchNetwork': False
}
}
],
'ideaType': 'KEYWORD',
'requestType': 'IDEAS',
'requestedAttributeTypes': ['KEYWORD_TEXT', 'SEARCH_VOLUME',
'CATEGORY_PRODUCTS_AND_SERVICES'],
'paging': {
'startIndex': str(offset),
'numberResults': str(PAGE_SIZE)
}
}
more_pages = True
while more_pages:
page = targeting_idea_service.get(selector)

# Display results.
if 'entries' in page:
for result in page['entries']:
attributes = {}
for attribute in result['data']:
attributes[attribute['key']] = getattr(attribute['value'], 'value',
'0')
print ('Keyword with "%s" text and average monthly search volume '
'"%s" was found with Products and Services categories: %s.'
% (attributes['KEYWORD_TEXT'],
attributes['SEARCH_VOLUME'],
attributes['CATEGORY_PRODUCTS_AND_SERVICES']))
print
else:
print ('No related keywords were found.')
offset += PAGE_SIZE
selector['paging']['startIndex'] = str(offset)
more_pages = offset < int(page['totalNumEntries'])


if __name__ == '__main__':
# Initialize client object.
adwords_client = adwords.AdWordsClient.LoadFromStorage()

main(adwords_client)



I know this is a very long post but I appreciate anyone who can help :)

Sreelakshmi Sasidharan (AdWords API Team)

unread,
Aug 25, 2017, 4:00:45 PM8/25/17
to AdWords API Forum
Hi Sarah, 

In addition to the OAuth credentials and the developer token you need to specify the client customer id in your googleads.yaml file . Please note that if you use the client customer id of a test account, the TargetingIdeaService will return dummy data. 

Please check this guide about Generating Targeting Ideas which explains about retrieving keyword ideas and retrieving keyword stats. The guide also compares keyword planner tool with the TargetingIdeaService. You are referring to the right code sample. If you need to get the stats corresponding to a given keyword, you will have to modify the requestType to 'STATS'. 

Thanks,
Sreelakshmi, AdWords API Team

sarah....@setnow.com

unread,
Aug 28, 2017, 5:01:46 PM8/28/17
to AdWords API Forum
This is the answer I keep getting everywhere. I have read all the docs and I still can't find a good answer, however it is possible I am reading over something. The point is that I do not have any client customers, nor do I want any. I am not trying to manage campaigns or any data from any accounts. I am just trying to do a simple keyword search using the keyword planner. Why do I need a client customer id? Regardless, I have tried putting that field into the .yaml file with my manager account id and my linked account's id (which I suppose could be considered my "client"), but I am still getting the same error.

Vincent Racaza (AdWords API Team)

unread,
Aug 28, 2017, 11:29:00 PM8/28/17
to AdWords API Forum
Hi Sarah,

I am a teammate of Sreelakshmi and I will provide support to you.

In using the TargetingIdeaService, a clientCustomerId is needed as the service proposed new keyword ideas based on your existing keywords and websites. Meaning, it is using a historical data using your client account.

Also, in your googleads.yaml file, kindly set your clientCustomerID instead of an MCC Id. If any issue occurs after doing the suggestion, kindly provide your SOAP request and response logs via reply privately to author so we can further investigate..

Thanks,
Vincent
AdWords API Team
Reply all
Reply to author
Forward
0 new messages