v13 Problem setting networkTargeting in python using SOAPpy

23 views
Skip to first unread message

Travis B

unread,
Nov 11, 2009, 3:44:15 PM11/11/09
to AdWords API Forum
Hi folks,

I can't seem to set the networkTargeting field using an updateCampaign
call on CampaignService. I'm using the SOAPpy framework in python.

The WSDL shows that geoTargeting is a complexType, just like
networkTargeting, however I am able to set the later simply using
dictionaries.

Any help is appreciated.

Here's some sample code that reproduces the problem:
BEGIN ADWORDS SAMPLE CODE>>>>>>>
import SOAPpy
from conf import config_dict

headers = SOAPpy.Types.headerType()

headers.email = config_dict['email']
headers.password = config_dict['password']
headers.useragent = config_dict['useragent']
headers.developerToken = config_dict['developerToken']
headers.applicationToken = config_dict['applicationToken']
headers.clientEmail = config_dict['clientEmail']

camp_service = SOAPpy.SOAPProxy('https://sandbox.google.com/api/
adwords/v13/CampaignService', header=headers)
camp_service.config.debug = 0

camp_service.getAllAdWordsCampaigns(0)
print camp_service.updateCampaign({'id': 1938, 'geoTargeting':
{'regionTargets': {'regions': ['US-CA']}}})
print camp_service.updateCampaign({'id': 1938, 'networkTargeting':
['SearchNetwork']})
<<<<<<<<<<<<<<END ADWORDS SAMPLE CODE


As shown, the second line produces:

SOAPpy.Types.faultType: <Fault soapenv:Server.userException:
java.lang.IllegalArgumentException: Can not set
com.google.ads.netapi.services.datamodel.NetworkTarget field
com.google.ads.netapi.services.campaign.CampaignData.networkTargeting
to [Ljava.lang.String;: <SOAPpy.Types.structType detail at
17938624>: ...


If I change the second call to:
print camp_service.updateCampaign({'id': 1938, 'networkTargeting':
{'networkTypes': ['SearchNetwork']}})

I get:
SOAPpy.Types.faultType: <Fault soapenv:Server.userException:
java.lang.IllegalArgumentException: Can not set
[Lcom.google.ads.netapi.services.datamodel.NetworkType; field
com.google.ads.netapi.services.datamodel.NetworkTarget.networkTypes to
[Ljava.lang.String;: <SOAPpy.Types.structType detail at
14784704>: ....

-Travis

AdWords API Advisor

unread,
Nov 11, 2009, 6:56:14 PM11/11/09
to AdWords API Forum
Hi Travis,

The short answer is that SOAPpy isn't readily compatible with the
AdWords API web services. Our web services are Document/Literal and
SOAPpy only support RPC/Encoded web services. It is possible to get
SOAPpy to a compatible format, but it takes a lot of manual
manipulation of the requests. The official AdWords API Python client
library has this functionality built in, and we recommend you use the
library instead of raw SOAPpy requests.

http://code.google.com/p/google-api-adwords-python-lib/

Best,
- Eric Koleda, AdWords API Team

Travis B

unread,
Nov 12, 2009, 12:10:38 PM11/12/09
to AdWords API Forum
Hi Eric,

So I've installed the python library, and I'm having trouble doing a
basic 'getAllAdWordsCampaigns' request against the sandbox. I'm having
trouble getting up and running with the library. I have a feeling I'm
not using it 100% correctly, but I based what I could off the sample
code.

I've got ZSI and PyXML installed on the system.

Bring on the sample code!
>>>>>>>>BEGIN SAMPLE CODE>>>>>>>>>
from qwobl_ads import config as ad_config

from aw_api.Client import Client

class GoogleAWAClient(object):
def __init__(self, email):
self._email = email
headers = {
'email': self._email,
'password': ad_config.google.password,
'clientCustomerId': 'Unknown',
'userAgent': ad_config.google.user_agent,
'developerToken': ad_config.google.developer_token,
'applicationToken': ad_config.google.application_token,
'validateOnly': 'n'
}

if(ad_config.google.version == 'sandbox'):
headers['clientEmail'] = 'client_1+' + self._email,

self.client = Client(headers=headers)

if __name__ == '__main__':
gc = GoogleAWAClient('q...@qwobl.com')
dummy = {'dummy': 0}
gc.client.CallMethod('https://sandbox.google.com/api/adwords/v13/
CampaignService',
'getAllAdWordsCampaigns', (dummy,), None)
<<<<<<<<<<<<<END SAMPLE CODE<<<<<<<<<<<<<<<<<<

And the error I get is:

Traceback (most recent call last):
File "aw_api_test.py", line 27, in <module>
'getAllAdWordsCampaigns', (dummy,), None)
File "/home/briggs/lib/python/aw_api/Client.py", line 601, in
CallMethod
request)
File "aw_api/WebService.py", line 330, in CallMethod
aw_api.Errors.Error/home/briggs/lib/python/aw_api/Errors.py:34:
DeprecationWarning: BaseException.message has been deprecated as of
Python 2.6
return str(self.message)
: 'tuple' object has no attribute 'find'


On Nov 11, 6:56 pm, AdWords API Advisor <adwordsapiadvi...@google.com>
wrote:

AdWords API Advisor

unread,
Nov 12, 2009, 2:57:15 PM11/12/09
to AdWords API Forum
Hi Travis,

There is a example that comes with the library that demonstrates how
to get all campaigns with the library:
http://code.google.com/p/google-api-adwords-python-lib/source/browse/trunk/demo/get_all_campaigns.py.
Are you able to run this example successfully?

Best,
- Eric
>     gc = GoogleAWAClient('...@qwobl.com')

Travis B

unread,
Nov 12, 2009, 4:28:42 PM11/12/09
to AdWords API Forum
Hi Eric,

I am able to run the example that comes with the library, but I was
hoping to integrate the library into our existing configuration system
rather than using the config script to generate pickled data files
that need to be read. I thought I could accomplish that using the
'headers' named parameter. Maybe I also need a 'config' named
parameter?

I want to avoid having to maintain the pickle files somewhere in my
source tree.

-Travis

On Nov 12, 2:57 pm, AdWords API Advisor <adwordsapiadvi...@google.com>
wrote:
> Hi Travis,
>
> There is a example that comes with the library that demonstrates how
> to get all campaigns with the library:http://code.google.com/p/google-api-adwords-python-lib/source/browse/....

AdWords API Advisor

unread,
Nov 16, 2009, 9:59:10 AM11/16/09
to AdWords API Forum
Hi Travis,

The pickle files aren't required for the library to work, and you
should be able to pass in your credentials to the constructor of the
Client. More information about the parameters for that constructor
can be found here: http://code.google.com/p/google-api-adwords-python-lib/source/browse/trunk/aw_api/Client.py#76.

Best,
- Eric
Reply all
Reply to author
Forward
0 new messages