是否有可用于使用 Python adwords 客户端的最新教程,或者是否有人知道足以取消以下内容?我是否犯了一些配置错误,或者可能不支持 Python 2.6?
在我安装的 Windows 上:
- 蟒蛇2.6
- setuptools-0.6c11.win32-py2.6.exe
- PyXML-0.8.4
- SOAPpy-0.12.4
- ZSI-2.0-rc3
- adwords_api_python_13.2.0
我已经为 AdWords 配置程序提供了 MCC 帐户电子邮件地址、密码、空白客户电子邮件和 ID,并且为开发人员令牌提供了附加了“+USD”的相同电子邮件地址。
现在,如果我使用 SOAPpy 作为 SOAP 库,我会得到一个关于意外关键字参数的异常,该异常timeout
已由 SOAPpy 中的一个函数提供给 SOAPpy 中的另一个函数。
如果我使用 ZSI 作为 SOAP 库(我认为这是首选),我会得到以下异常:
Traceback (most recent call last):
File "tutorial.py", line 36, in <module>
campaigns = campaign_service.Mutate(operations)[0]
File "c:\Python26\lib\site-packages\adspygoogle\adwords\CampaignService.py", l
ine 112, in Mutate
'Campaign', self._loc, request)
File "c:\Python26\lib\site-packages\adspygoogle\adwords\AdWordsWebService.py",
line 256, in CallMethod
self.__ManageSoap(buf, start_time, stop_time, error)
File "c:\Python26\lib\site-packages\adspygoogle\adwords\AdWordsWebService.py",
line 130, in __ManageSoap
raise Error(e)
adspygoogle.common.Errors.Error:
Traceback (most recent call last):
File "c:\Python26\lib\site-packages\adspygoogle\common\WebService.py", line 20
8, in CallMethod
eval('service.%s(request)' % method_name))
File "<string>", line 1, in <module>
File "c:\Python26\lib\site-packages\adspygoogle\adwords\zsi\v201008\CampaignSe
rvice_services.py", line 47, in mutateCampaign
self.binding.Send(None, None, request, soapaction="", **kw)
File "build\bdist.win32\egg\ZSI\client.py", line 267, in Send
self.SendSOAPData(soapdata, url, soapaction, **kw)
File "build\bdist.win32\egg\ZSI\client.py", line 301, in SendSOAPData
self.h.send(soapdata)
File "c:\Python26\lib\site-packages\adspygoogle\common\zsi\HttpsConnectionHand
ler.py", line 93, in send
httplib.HTTPSConnection.endheaders(self)
File "c:\Python26\lib\httplib.py", line 892, in endheaders
self._send_output()
File "c:\Python26\lib\httplib.py", line 764, in _send_output
self.send(msg)
File "c:\Python26\lib\site-packages\adspygoogle\common\zsi\HttpsConnectionHand
ler.py", line 93, in send
httplib.HTTPSConnection.endheaders(self)
File "c:\Python26\lib\httplib.py", line 890, in endheaders
raise CannotSendHeader()
CannotSendHeader [RAW DATA: _________________________________ Tue Mar 08 16:54:4
0 2011 REQUEST:
接下来是一些 XML,我对其进行了修改以删除识别数据:
<SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xm
lns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ZSI="http://www.z
olera.com/schemas/ZSI/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Header><RequestHeader xmlns
="https://adwords.google.com/api/adwords/cm/v201008"><authToken>XYZ</authToken>
<userAgent>AwApi-Python-13.2.0|XYZ</userAgent><developerTok
en>XYZ@gmail.com+USD</developerToken></RequestHeader></SOAP-ENV:Header><SO
AP-ENV:Body xmlns:ns1="https://adwords.google.com/api/adwords/cm/v201008"><ns1:m
utate xmlns:ns1="https://adwords.google.com/api/adwords/cm/v201008"><ns1:operati
ons><ns1:operator>ADD</ns1:operator><ns1:operand><ns1:name>Interplanetary Cruise
#201138165440485000</ns1:name><ns1:status>PAUSED</ns1:status><ns1:endDate>20120
101</ns1:endDate><ns1:budget xsi:type="ns1:Budget"><ns1:period>DAILY</ns1:period
><ns1:amount xsi:type="ns1:Money"><ns1:microAmount>50000000</ns1:microAmount></n
s1:amount><ns1:deliveryMethod>STANDARD</ns1:deliveryMethod></ns1:budget><ns1:bid
dingStrategy xsi:type="ns1:ManualCPC"></ns1:biddingStrategy></ns1:operand></ns1:
operations></ns1:mutate></SOAP-ENV:Body></SOAP-ENV:Envelope>
我的代码如下:
from adspygoogle.adwords.AdWordsClient import AdWordsClient
from adspygoogle.common import Utils
client = AdWordsClient(path = '../../installers/adwords_api_python_13.2.0.tar/adwords_api_python_13.2.0')
campaign_service = client.GetCampaignService('https://adwords-sandbox.google.com', 'v201008')
operations = [{
'operator': 'ADD',
'operand': {
'name': 'Interplanetary Cruise #%s' % Utils.GetUniqueName(),
'status': 'PAUSED',
'biddingStrategy': {
'type': 'ManualCPC'
},
'endDate': '20120101',
'budget': {
'period': 'DAILY',
'amount': {
'microAmount': '50000000'
},
'deliveryMethod': 'STANDARD'
}
}
}]
campaigns = campaign_service.Mutate(operations)[0]
# Display results.
for campaign in campaigns['value']:
print ('Campaign with name \'%s\' and id \'%s\' was added.'
% (campaign['name'], campaign['id']))
print
print ('Usage: %s units, %s operations' % (client.GetUnits(),
client.GetOperations()))
请注意,http://code.google.com/apis/adwords/docs/tutorial.htmlaw_api.Client
上的教程代码甚至没有一点作用,在当前版本的客户端中没有这样的东西。但以上内容大多是从教程中复制而来的。
客户端提供的示例会导致相同的错误。
如果当前的客户端库只是损坏了,我可以尝试一个较旧的客户端库,但如果它有任何区别,我将需要一个支持 TargetingIdeaService 的客户端库。
[编辑:哦,对不起,我忘了说我实际上编辑了 AdWords 客户端代码。在 Utils.GetDataFromCsvFile 中,我.replace(':','|')
从构造传递给urllib.urlopen
.
这就是让我怀疑我的 Python 版本可能不受支持的原因,因为 Windows Python 2.6 似乎无法打开 url file:///c|/foo/bar/baz/
]