error when using TargetingIdeaService to get STATS

127 views
Skip to first unread message

Daphna Wegner

unread,
May 16, 2016, 4:36:52 PM5/16/16
to AdWords API Forum

Hi,

I am getting an error when trying to make a request to TargetingIdeaService, here is how I make the call (using python):

    PAGE_SIZE = 100
    kw_search_volume = []
    # Initialize appropriate service.
    targeting_idea_service = client.GetService('TargetingIdeaService', version='v201509')

    # Construct selector object and retrieve related keywords.
    offset = 0
    selector = {
      'searchParameters': [
          {
              'xsi_type': 'RelatedToQuerySearchParameter',
              'queries': keywords (** a list of keywords - always under the 800 limit)
          },
      ],
      'ideaType': 'KEYWORD',
      'requestType': 'STATS',
      'requestedAttributeTypes': ['KEYWORD_TEXT', 'SEARCH_VOLUME'],
      '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 \'%s\'  average monthly search volume '
                   '\'%s\n'
                   % (attributes['KEYWORD_TEXT'],
                      attributes['SEARCH_VOLUME']))

            kw_volume = {}
            kw_volume['keyword'] = attributes['KEYWORD_TEXT']
            kw_volume['volume'] = attributes['SEARCH_VOLUME']
            kw_search_volume.append(kw_volume)
          print
        else:
          print 'No related keywords were found.'
        offset += PAGE_SIZE
        selector['paging']['startIndex'] = str(offset)
        more_pages = offset < int(page['totalNumEntries'])


Here is the error message:
Server raised fault: '[DistinctError.DUPLICATE_ELEMENT @ selector.searchParameters[0].queries[154], DistinctError.DUPLICATE_ELEMENT @ selector.searchParameters[0].queries[289]]'

Not sure what is the duplicates referring to


Joyce Lava

unread,
May 16, 2016, 4:55:17 PM5/16/16
to AdWords API Forum
Hi Daphna,

DistinctError.DUPLICATE_ELEMENT occurs when the request has duplicate parameters. Please check if you have duplicate parameters before making the request.

If you find out that there are no duplicate or identical parameters, please Reply Privately to Author the SOAP request and response so I can look into it further.

Thanks,
Joyce, AdWords API Team

Daphna Wegner

unread,
May 16, 2016, 5:43:12 PM5/16/16
to AdWords API Forum
Thanks Joyce! 

I will send you the SOAP request, one more thing I am noticing is that the error is inconsistent, I would sometimes get it and then sometimes get the following error using the same code and keywords:

'ascii' codec can't decode byte 0xe6 in position 13: ordinal not in range(128)

Joyce Lava

unread,
May 16, 2016, 6:53:28 PM5/16/16
to AdWords API Forum
Hi Daphna,

This seems to be an issue with how suds handles Unicode in Python 2. However, as a workaround, you need to send Unicode content in a Unicode string rather than encoding it.

You can change your default encoding as seen in PEP 0263 and use those characters directly.

Daphna Wegner

unread,
May 16, 2016, 7:24:14 PM5/16/16
to AdWords API Forum
Thanks for letting me know I will try to change that.

I am still getting the other error:
DistinctError.DUPLICATE_ELEMENT

I have sent you a private message with the SOAP request 

Thanks,
Daphna

Daphna Wegner

unread,
May 17, 2016, 2:19:29 AM5/17/16
to AdWords API Forum
Hi Joyce,

I was able to resolve the DUPLICTE error however I am not sure how to resolve this suds unicode problem, I tried PEP 0263 suggestion but thats not doing anything can you please elaborate on how to resolve this issue, we are unable to move forward without resolving this problem.

Thanks,
Daphna

Joyce Lava

unread,
May 17, 2016, 10:39:58 AM5/17/16
to AdWords API Forum
Hi Daphna,

Sorry for the delay. Glad to hear that the DUPLICATE_ELEMENT error was fixed.

For this ascii error, you can file an issue in the python client library's issue tracker to track the analysis and resolution of this problem.
Reply all
Reply to author
Forward
0 new messages