Hello,

I'm using TargetingIdeaService from Adwords API. I'm trying to catch any 
exception happening during the requests, sleep for 31 seconds, then retry. 
However, it seems that there are some exceptions occurring in the library 
files that I wonder how can I handle them? Here is a snippet of my code 
which is intended to send a set of kewords and return some statistics such 
as CPC, search volume, etc.:

def getRequest(selector, targeting_idea_service):
 page = targeting_idea_service.get(selector)
 while True:

 try: 

 # Get

 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 result

 money = {}

 money = attributes['AVERAGE_CPC']

 cpc  = money['microAmount'] 

 out = ""

 out =  "{'" + str(attributes['KEYWORD_TEXT']) + "': {'CPC': " + str(cpc) + ", 
'SV': " + str(attributes['SEARCH_VOLUME']) + ", 'CR': " + str(attributes[
'COMPETITION']) + "}}"

 print out

 else:

 print 'No related keywords were found.'

 except suds.WebFault as detail:

 print detail

 print "Sleeping WebFault"

 time.sleep(31) 

 continue

 except Exception as e:

 print e

 print "Sleeping"

 time.sleep(31)          

 continue

 break

I'm using Python 2.7 and googleads API v. 5 and v. 4.7 with my test account

Here is the traceback for googleads version 5:

Traceback (most recent call last):

  File "cpc2.py", line 165, in <module>

    main(sys.argv[1:])

  File "cpc2.py", line 149, in main

    getRequest(selector, targeting_idea_service)

  File "cpc2.py", line 52, in getRequest

    page = targeting_idea_service.get(selector)

  File "/Library/Python/2.7/site-packages/googleads/common.py", line 700, 
in MakeSoapRequest

    *[_PackForSuds(arg, self.suds_client.factory) for arg in args])

  File "/Library/Python/2.7/site-packages/suds/client.py", line 521, in 
__call__

    return client.invoke(args, kwargs)

  File "/Library/Python/2.7/site-packages/suds/client.py", line 581, in 
invoke

    result = self.send(soapenv)

  File "/Library/Python/2.7/site-packages/suds/client.py", line 613, in send

    reply = self.options.transport.send(request)

  File "/Library/Python/2.7/site-packages/googleads/util.py", line 98, in 
PatchedHttpTransportSend

    fp = self.u2open(u2request)

  File "/Library/Python/2.7/site-packages/suds/transport/http.py", line 
132, in u2open

    return url.open(u2request, timeout=tm)

  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
 
line 437, in open

    response = meth(req, response)

  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
 
line 550, in http_response

    'http', request, response, code, msg, hdrs)

  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
 
line 475, in error

    return self._call_chain(*args)

  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
 
line 409, in _call_chain

    result = func(*args)

  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
 
line 558, in http_error_default

    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)

urllib2.HTTPError: HTTP Error 500: Internal Server Error
Traceback for version 4.7:

Traceback (most recent call last):

  File "cpc2.py", line 165, in <module>

    main(sys.argv[1:])

  File "cpc2.py", line 149, in main

    getRequest(selector, targeting_idea_service)

  File "cpc2.py", line 52, in getRequest

    page = targeting_idea_service.get(selector)

  File "/Library/Python/2.7/site-packages/googleads/common.py", line 647, 
in MakeSoapRequest

    raise e

suds.WebFault: Server raised fault: '[RateExceededError 
<rateName=RATE_LIMIT, rateKey=null, rateScope=ACCOUNT, 
retryAfterSeconds=30>]'


Any advice in how to handle this exception in away that my function will 
sleep for a while then continue trying?

Thank you



-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@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 Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@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/7f555be7-211d-4063-b841-294b505ec505%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to