wsdl2py请求

时间:2010-03-03 23:51:34

标签: python soap wsdl

我正在尝试从名为Chrome ADS的SOAP服务(用于车辆数据)中获取结果。他们提供了php和Java示例,但我需要python(我们的站点在Django中)。我的问题是:

使用wsdl2py生成的类时,我应该将什么作为请求传递给SOAP服务?

按照示例我使用DataVersionsRequest对象作为请求参数,但是wsdl2py生成的代码似乎需要一个getDataVersions对象,并且在生成的_client.py文件的底部定义了类似的东西。但这似乎也是一个错误。所以我不确定我应该传递什么作为请求obj。有什么建议吗?

$sudo apt-get install python-zsi
$wsdl2py http://platform.chrome.com/***********
$python 
>>> url = "http://platform.chrome.com/***********"
>>> from AutomotiveDescriptionService6_client import *
>>> from AutomotiveDescriptionService6_types import *
>>> locator = AutomotiveDescriptionService6Locator()
>>> service = locator.getAutomotiveDescriptionService6Port()
>>> locale = ns0.Locale_Def('locale')
>>> locale._country="US"
>>> locale._language="English"
>>> acctInfo = ns0.AccountInfo_Def('accountInfo')
>>> acctInfo._accountNumber=*****
>>> acctInfo._accountSecret="*****"
>>> acctInfo._locale = locale
>>> dataVersionsRequest = ns0.DataVersionsRequest_Dec()
>>> dataVersionsRequest._accountInfo = acctInfo
>>> service.getDataVersions(dataVersionsRequest)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "AutomotiveDescriptionService6_client.py", line 36, in getDataVersions
    raise TypeError, "%s incorrect request type" % (request.__class__)
TypeError: <class 'AutomotiveDescriptionService6_types.DataVersionsRequest_Dec'> incorrect request type
>>> dataVersionsRequest = getDataVersions
>>> dataVersionsRequest._accountInfo = acctInfo
>>> service.getDataVersions(dataVersionsRequest)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "AutomotiveDescriptionService6_client.py", line 36, in getDataVersions
    raise TypeError, "%s incorrect request type" % (request.__class__)
AttributeError: class DataVersionsRequest_Holder has no attribute '__class__'
>>> quit()
$cat AutomotiveDescriptionService6_client.py
.....
# Locator
class AutomotiveDescriptionService6Locator:
    AutomotiveDescriptionService6Port_address = "http://platform.chrome.com:80/AutomotiveDescriptionService/AutomotiveDescriptionService6"
    def getAutomotiveDescriptionService6PortAddress(self):
        return AutomotiveDescriptionService6Locator.AutomotiveDescriptionService6Port_address
    def getAutomotiveDescriptionService6Port(self, url=None, **kw):
        return AutomotiveDescriptionService6BindingSOAP(url or AutomotiveDescriptionService6Locator.AutomotiveDescriptionService6Port_address, **kw)

# Methods
class AutomotiveDescriptionService6BindingSOAP:
    def __init__(self, url, **kw):
        kw.setdefault("readerclass", None)
        kw.setdefault("writerclass", None)
        # no resource properties
        self.binding = client.Binding(url=url, **kw)
        # no ws-addressing

    # op: getDataVersions
    def getDataVersions(self, request, **kw):
        if isinstance(request, getDataVersions) is False:
            raise TypeError, "%s incorrect request type" % (request.__class__)
        # no input wsaction
        self.binding.Send(None, None, request, soapaction="", **kw)
        # no output wsaction
        response = self.binding.Receive(getDataVersionsResponse.typecode)
        return response
.....
getDataVersions = GED("urn:description6.kp.chrome.com", "DataVersionsRequest").pyclass

另外,另外,我不确定我传递给pname参数的字符串是否正确,我认为当我使用SOAP UI浏览服务时,这些是我在XML中看到的那些,对吧?

2 个答案:

答案 0 :(得分:1)

看起来你可能第二次将一个类传递给service.getDataVersions()而不是一个实例(如果它没有__class __则它不能是一个实例)。

正在发生的事情是isinstance()返回false,并且在尝试引发类型错误的过程中,会引发属性错误,因为它试图访问显然不存在的__class__。

如果你尝试会发生什么:

>>> dataVersionsRequest = getDataVersions**()**
>>> dataVersionsRequest._accountInfo = acctInfo
>>> service.getDataVersions(dataVersionsRequest)

基于这一行:

if isinstance(request, getDataVersions) is False:
            raise TypeError, "%s incorrect request type" % (request.__class__)

看起来你应该传递一个getDataVersions实例,所以你可能在正确的轨道上。

答案 1 :(得分:0)

您可能需要实例化定义对象然后填充它们。查找与您想要进行的请求相关联的type == pyclass_type对象并实例化它们。

e.g。 (只是猜测)

>>> versionrequest = getDataVersions()
>>> versionrequest.AccountInfo = versionrequest.new_AccountInfo()
>>> versionrequest.AccountInfo.accountNumber = "123"
>>> versionrequest.AccountInfo.accountSecret = "shhhh!"
>>> service.getDataVersions(versionrequest)

我发现wsdl2py生成的代码对我来说太慢了。祝你好运。