use*_*450 4 python soap wsdl suds
我正在使用suds向第三方API发出SOAP请求.
import suds.client
client = suds.client.Client(WSDL_URL, location=SERVICE_URL)
Run Code Online (Sandbox Code Playgroud)
当我尝试为WSDL定义的特定类型创建一个对象时(比如说TheObject):
obj = client.factory.create('TheObject')
Run Code Online (Sandbox Code Playgroud)
我收到一个关于它不存在的错误:
(TheObject) not-found
path: "TheObject", not-found
Traceback (most recent call last):
File "suds_test.py", line 67, in <module>
sys.exit(main(sys.argv))
File "suds_test.py", line 51, in main
obj = client.factory.create('TheObject'),
File "/usr/local/lib/python2.7/dist-packages/suds/client.py", line 234, in create
raise TypeNotFound(name)
suds.TypeNotFound: Type not found: 'TheObject'
Run Code Online (Sandbox Code Playgroud)
所以,我打印可用肥皂水工厂类型列表有print(client):
Suds ( https://fedorahosted.org/suds/ ) version: 0.4 GA build: R699-20100913
Service ( OrderService ) tns="http://api.example.com/services/"
Prefixes (2)
ns0 = "http://api.example.com/contracts/stuff"
ns1 = "http://api.example.com/services/"
Ports (2):
(OrderServiceSoap)
Methods (123):
... Not really relevant
Types (123):
SomeType
SomeType2
ns0:AnotherType
ns0:AnotherType2
ns0:TheObject
...
Run Code Online (Sandbox Code Playgroud)
所以它似乎ns1是默认命名空间,并且ns0是我想要用于的命名空间TheObject.如果我用命名空间别名作为前缀,它就可以工作.
obj = client.factory.create('ns0:TheObject')
Run Code Online (Sandbox Code Playgroud)
我宁愿不记得ns0在这种特殊情况下使用,因为它随意变化.我查找了文档,Factory.create()但它只接受一个参数名称,没有名称空间URL或任何其他参数.
有没有办法动态确定命名空间TheObject?或者是否可以指定整个URL ns0而不仅仅是命名空间别名?任何帮助,将不胜感激.
我应该很明显它是一个标准的XML命名空间,并且在文档中清楚地表明了(我错过了).
要通过URL指定命名空间,只需在名称前加上包含在{}(花括号)中的命名空间URL :
obj = client.factory.create('{http://api.example.com/contracts/stuff}TheObject')
Run Code Online (Sandbox Code Playgroud)