Hi, I think the problem may be that you are forcing a refresh of the OAuth2 token in every thread. Do you still get the error if you remove the credentials.refresh(httplib2.Http()) line? The library should take care of refreshing your access token if it has expired so you shouldn't have to force it before each call.
Cheers, Josh, AdWords API Team On Tuesday, March 25, 2014 8:25:38 AM UTC-4, sitaram krishna wrote: > > Hi, > > Forgive me if this is a very trivial question. > > I am trying to use the TargetingIdeaService to get kw suggestions. > This was working fine with when I run single threaded it runs fine, but > when run multi threaded it fails with error: "Unable to parse SOAP buffer > for outgoing messages. not well-formed (invalid token): line 1, column 0" > > I am using *adspygoogle*=1.1.6* api_version*=v201309 > > //keywords.py attachment contains GoogleKeywords class > > Code Snippet:--- > import threading > import datetime > > class ThreadClass(threading.Thread): > def __init__(self, url): > threading.Thread.__init__(self) > self._url = url > > def run(self): > CLIENT_ID = 'xxxx' > CLIENT_SECRET = 'xxxxx' > REFRESH_TOKEN = 'xxxx' > credentials = OAuth2Credentials( > access_token='--expired--', > client_id=CLIENT_ID, > client_secret=CLIENT_SECRET, > refresh_token=REFRESH_TOKEN, > token_expiry=None, > token_uri='https://accounts.google.com/o/oauth2/token', > user_agent='xxxx') > credentials.refresh(httplib2.Http()) > headers = { > "userAgent" : 'xxxx', > "developerToken" : 'xxxx', > "validateOnly" : "n", > "oauth2credentials": credentials, > "clientCustomerId" : 'xxxx' > } > > client_config = { > "soap_lib" : adspygoogle.common.soappy, > "compress" : "y", > "xml_parser" : adspygoogle.common.ETREE, > "debug" : "n", > "raw_debug" : "n", > } > > client = AdWordsClient(headers=headers, config=client_config) > targeting_idea_service = client.GetTargetingIdeaService(' > https://adwords.google.com') > keywords = GoogleKeywords(None,targeting_idea_service) //Class > is implemented in keywords.py > print keywords.getRelatedKeywordsForUrl(self._url) > > urls = [' > http://www.hardtail-mtb.com/specialized-s-works-stumpjumper-fsr-carbon-evo-mountain-bike-2014-full-suspension-mtb.html > ', > ' > http://www.hardtail-mtb.com/rocky-mountain-element-970-rsl-bike-2013.html > ', > ' > http://www.hardtail-mtb.com/specialized-s-works-stumpjumper-fsr-carbon-evo-mountain-bike-2014-full-suspension-mtb.html > ', > ' > http://www.hardtail-mtb.com/rocky-mountain-element-970-rsl-bike-2013.html > '] > > for i in range(4): > t = ThreadClass(urls[i]) > t.start() > -- -- =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ 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 [email protected] To unsubscribe from this group, send email to [email protected] 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
