如何将suds调用从php转换为python

时间:2012-07-19 09:04:29

标签: python arrays struct wsdl suds

我在php中有一个示例代码:

$conditions = Array(
    "status_id" => "1"    
);
$params = Array(
    "method" => "call",
    "params" => Array($session, "order.list.filter", 
            Array($conditions, "order_id", 10) 
        )

我无法找到如何将其翻译为python。

我有代码:

imp = Import('http://schemas.xmlsoap.org/soap/encoding/')
imp.filter.add('http://decorations.pl/webapi/soap/')
doctor = ImportDoctor(imp) 
url = 'http://decorations.pl/webapi/soap/?wsdl'
print url
client = Client(url, doctor=doctor)
print client

这让我:

Suds ( https://fedorahosted.org/suds/ )  version: 0.4 GA  build: R699-20100913
Service ( Webapi_Soap_ApiService ) tns="http://decorations.pl/webapi/soap/"
  Prefixes (1)
   ns0 = "http://schemas.xmlsoap.org/soap/encoding/"
  Ports (1):
   (Webapi_Soap_ApiPort)
     Methods (11):
        aquireApplicationLock(xs:string session, xs:string message, xs:boolean stealLock, )
        call(xs:string session, xs:string function, xs:anyType arguments, )
        checkApplicationLock(xs:string session, )
        checkObjectListModificationTime(xs:string session, xs:int objectType, ns0:Array list, )
        checkObjectLock(xs:string session, xs:int objectType, xs:int id, )
        checkObjectModificationTime(xs:string session, xs:int objectType, xs:int id, )
        getApplicationLock(xs:string session, )
        login(xs:string login, xs:string password, )
        logout(xs:string session, )
        releaseApplicationLock(xs:string session, xs:boolean stealLock, )
        updateApplicationLock(xs:string session, xs:boolean stealLock, )
     Types (48):
        ns0:Array
        ns0:ENTITIES
        ns0:ENTITY
        ns0:ID
        ns0:IDREF
        ns0:IDREFS
        ns0:NCName
        ns0:NMTOKEN
        ns0:NMTOKENS
        ns0:NOTATION
        ns0:Name
        ns0:QName
        ns0:Struct
        ns0:anyURI
        ns0:arrayCoordinate
        ns0:base64
        ns0:base64Binary
        ns0:boolean
        ns0:byte
        ns0:date
        ns0:dateTime
        ns0:decimal
        ns0:double
        ns0:duration
        ns0:float
        ns0:gDay
        ns0:gMonth
        ns0:gMonthDay
        ns0:gYear
        ns0:gYearMonth
        ns0:hexBinary
        ns0:int
        ns0:integer
        ns0:language
        ns0:long
        ns0:negativeInteger
        ns0:nonNegativeInteger
        ns0:nonPositiveInteger
        ns0:normalizedString
        ns0:positiveInteger
        ns0:short
        ns0:string
        ns0:time
        ns0:token
        ns0:unsignedByte
        ns0:unsignedInt
        ns0:unsignedLong
        ns0:unsignedShort

我不知道如何建立工作电话...... 我有函数调用'order.list.filter':

# after login...
conditions = ""
params = client.factory.create('ns0:Array')
params.Array = [ conditions , "order_id", 10]
lista = client.service.call(sesId, 'order.list.filter', parametry)
print lista

给了我:

[1, 9, 10, 11, 12, 13, 14, 15, 16, 17]

但我不能建立条件给我像PHP的结果。 我尝试使用'ns0:Struct'找到一些例子,但我不能编写代码,但不是以:

结尾
File ".\test.py", line 143, in <module>
  lista = client.service.call(sesId, 'order.list.filter', parametry)
File "build\bdist.win32\egg\suds\client.py", line 542, in __call__
File "build\bdist.win32\egg\suds\client.py", line 602, in invoke
File "build\bdist.win32\egg\suds\client.py", line 649, in send
File "build\bdist.win32\egg\suds\client.py", line 702, in failed
File "build\bdist.win32\egg\suds\bindings\binding.py", line 265, in get_fault
suds.WebFault: Server raised fault: 'Unknown error'

1 个答案:

答案 0 :(得分:0)

我将在这里走出困境并假设$conditions变量的python等价物是:

conditions = {'status_id': 1}

因为我不知道其他变量是什么,我无法真正告诉如何构造等价的$params