使用Python/Suds调用带点的SOAP方法

2 投票
2 回答
5033 浏览
提问于 2025-04-16 09:35

我在用Python的Suds库进行SOAP调用。它能顺利导入WSDL文件,生成的客户端看起来也没问题,但我就是无法访问里面的方法。

Suds的文档里是这样描述方法调用的:

client.service.Company.GetQueue()

但是我尝试了各种变体,得到的结果都是:

suds.MethodNotFound: 找不到方法: 'OmnitureWebService.OmnitureWebServicePort.Company'

这是我创建的客户端的变量信息。你可以看到方法确实存在,但我该怎么访问它们呢?我试过指定端口、指定前缀,但都没有效果。谢谢任何帮助。

> obj._ServiceSelector__client =  Suds (
> https://fedorahosted.org/suds/ ) 
> version: 0.4 GA  build: R699-20100913
> 
> Service ( OmnitureWebService )
> tns="http://www.omniture.com/"   
> Prefixes (2)
>       ns0 = "http://schemas.xmlsoap.org/soap/encoding/"
>       ns1 = "http://www.omniture.com/"    Ports (1):
>       (OmnitureWebServicePort)
>          Methods (173):
>             CodeManager.DeleteCodeArchive(xs:int
> archive_id, )
>             CodeManager.GenerateCode(xs:string
> char_set, xs:string code_type, xs:int
> cookie_domain_periods, xs:string
> currency_code, xs:string rsid, xs:int
> secure, )
>             CodeManager.GetCodeArchives(int_array
> archive_id_list, xs:string
> binary_encoding, xs:int
> populate_code_items, )
>             CodeManager.SaveCodeArchive(xs:string
> archive_description, xs:int
> archive_id, xs:string archive_name,
> code_items code, )
>             Company.CancelQueueItem(xs:int qid, )
>             Company.DownloadProduct(productType
> productType, )
>             Company.GetEndpoint(xs:string company,
> )
>             Company.GetQueue()
>             Company.GetReportSuites(string_array
> rs_types, xs:string sp, )
>             Company.GetTokenCount()
>             Company.GetTokenUsage()
>             Company.GetTrackingServer(xs:string
> rsid, )
>             Company.ResetTokenCount(xs:string
> auth_key, )

2 个回答

0

哦,明白了。看起来在命名空间中使用的“.”在XML中是可以的,但在Suds中会出现问题。我试过去掉这个“.”,但是Suds也会缓存WSDL。这里有个解决办法:

https://fedorahosted.org/suds/wiki/TipsAndTricks

页面下方还有关于如何关闭缓存的说明。

5

kfed说得对,问题出在那些点上。不过我不想去修改我的WSDL。

不过,我找到了一种解决办法:
可以用getattr来通过字符串引用方法名,获取到这个方法的句柄,然后再调用它:

Company_GetTokenCount = getattr(client.service, 'Company.GetTokenCount')
Company_GetTokenCount()

https://fedorahosted.org/suds/ticket/253
我:Suds版本0.4 GA构建:R699-20100913

撰写回答