gpt4 book ai didi

python - 导入命名空间后出现 TypeNotFoundError

转载 作者:太空狗 更新时间:2023-10-30 00:17:24 25 4
gpt4 key购买 nike

我在 Python(2.7) 中的应用程序应该使用客户端来使用 WSDL 中描述的 SOAP Web 服务(由 Magento(1.7.0) 生成并在最后发布)。

为此任务选择了 Suds(4.0),当我尝试连接这些代码时:

from suds.client import Client       
client = Client(url)

由于此处描述的一个众所周知的问题,我收到了 TypeNotFound 错误 https://fedorahosted.org/suds/wiki/Documentation#FIXINGBROKENSCHEMAs

然后我将我的代码更改为:

from suds.client import Client
from suds.xsd.doctor import Import, ImportDoctor
#Fixing the import
imp = Import('http://schemas.xmlsoap.org/soap/encoding/')
imp.filter.add('urn:Magento')
client = Client(self.url, plugins=[ImportDoctor(imp)] )
#Now Authentication
session = client.service.login(username, password)
#Call a method
client.service.call(session,'catalog_product.info',['123'])

但是,现在出现了一个新的Exception:

File "/home/david.gonzalez/.virtualenvs/testlib/lib/python2.7/site- packages/suds/mx/literal.py", line 86, in start
raise TypeNotFound(content.tag)
suds.TypeNotFound: Type not found: 'args'

我不明白,如果在 wsdl 中是显式的,为什么它找不到 'args' 的类型:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:typens="urn:Magento" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Magento" targetNamespace="urn:Magento">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
<!--
<import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />
-->
<complexType name="FixedArray">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:anyType[]" />
</restriction>
</complexContent>
</complexType>
</schema>
</types>
<message name="call">
<part name="sessionId" type="xsd:string" />
<part name="resourcePath" type="xsd:string" />
<part name="args" type="xsd:anyType" />
</message>
<message name="callResponse">
<part name="callReturn" type="xsd:anyType" />
</message>
<message name="multiCall">
<part name="sessionId" type="xsd:string" />
<part name="calls" type="typens:FixedArray" />
<part name="options" type="xsd:anyType" />
</message>
<message name="multiCallResponse">
<part name="multiCallReturn" type="typens:FixedArray" />
</message>
<message name="endSession">
<part name="sessionId" type="xsd:string" />
</message>
<message name="endSessionResponse">
<part name="endSessionReturn" type="xsd:boolean" />
</message>
<message name="login">
<part name="username" type="xsd:string" />
<part name="apiKey" type="xsd:string" />
</message>
<message name="loginResponse">
<part name="loginReturn" type="xsd:string" />
</message>
<message name="resources">
<part name="sessionId" type="xsd:string" />
</message>
<message name="resourcesResponse">
<part name="resourcesReturn" type="typens:FixedArray" />
</message>
<message name="globalFaults">
<part name="sessionId" type="xsd:string" />
</message>
<message name="globalFaultsResponse">
<part name="globalFaultsReturn" type="typens:FixedArray" />
</message>
<message name="resourceFaults">
<part name="resourceName" type="xsd:string" />
<part name="sessionId" type="xsd:string" />
</message>
<message name="resourceFaultsResponse">
<part name="resourceFaultsReturn" type="typens:FixedArray" />
</message>
<message name="startSession" />
<message name="startSessionResponse">
<part name="startSessionReturn" type="xsd:string" />
</message>
<portType name="Mage_Api_Model_Server_HandlerPortType">
<operation name="call">
<documentation>Call api functionality</documentation>
<input message="typens:call" />
<output message="typens:callResponse" />
</operation>
<operation name="multiCall">
<documentation>Multiple calls of resource functionality</documentation>
<input message="typens:multiCall" />
<output message="typens:multiCallResponse" />
</operation>
<operation name="endSession">
<documentation>End web service session</documentation>
<input message="typens:endSession" />
<output message="typens:endSessionResponse" />
</operation>
<operation name="login">
<documentation>Login user and retrive session id</documentation>
<input message="typens:login" />
<output message="typens:loginResponse" />
</operation>
<operation name="startSession">
<documentation>Start web service session</documentation>
<input message="typens:startSession" />
<output message="typens:startSessionResponse" />
</operation>
<operation name="resources">
<documentation>List of available resources</documentation>
<input message="typens:resources" />
<output message="typens:resourcesResponse" />
</operation>
<operation name="globalFaults">
<documentation>List of resource faults</documentation>
<input message="typens:globalFaults" />
<output message="typens:globalFaultsResponse" />
</operation>
<operation name="resourceFaults">
<documentation>List of global faults</documentation>
<input message="typens:resourceFaults" />
<output message="typens:resourceFaultsResponse" />
</operation>
</portType>
<binding name="Mage_Api_Model_Server_HandlerBinding" type="typens:Mage_Api_Model_Server_HandlerPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="call">
<soap:operation soapAction="urn:Mage_Api_Model_Server_HandlerAction" />
<input>
<soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
<operation name="multiCall">
<soap:operation soapAction="urn:Mage_Api_Model_Server_HandlerAction" />
<input>
<soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
<operation name="endSession">
<soap:operation soapAction="urn:Mage_Api_Model_Server_HandlerAction" />
<input>
<soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
<operation name="login">
<soap:operation soapAction="urn:Mage_Api_Model_Server_HandlerAction" />
<input>
<soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
<operation name="startSession">
<soap:operation soapAction="urn:Mage_Api_Model_Server_HandlerAction" />
<input>
<soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
<operation name="resources">
<soap:operation soapAction="urn:Mage_Api_Model_Server_HandlerAction" />
<input>
<soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
<operation name="globalFaults">
<soap:operation soapAction="urn:Mage_Api_Model_Server_HandlerAction" />
<input>
<soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
<operation name="resourceFaults">
<soap:operation soapAction="urn:Mage_Api_Model_Server_HandlerAction" />
<input>
<soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>
<service name="MagentoService">
<port name="Mage_Api_Model_Server_HandlerPort" binding="typens:Mage_Api_Model_Server_HandlerBinding">
<soap:address location="http://127.0.0.1/magento/index.php/api/soap/index/" />
</port>
</service>
</definitions>

我的感觉是命名空间的名称有误,但是,我已经尝试过这个线程,结果相同: SOAP suds and the dreaded schema Type Not Found error

最佳答案

这是你的电话:

client.service.call(session,'catalog_product.info',['123']) # <--- ['123']

也许它需要 xsd:anyType[] 才能工作; i.o.w. anyType 而不是 anyType 的数组。

<message name="call">
<part name="sessionId" type="xsd:string" />
<part name="resourcePath" type="xsd:string" />
<part name="args" type="xsd:anyType[]" />
</message>

关于python - 导入命名空间后出现 TypeNotFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24397735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com