我正在尝试连接到“RSA Archer”网络服务。我针对连接的测试服务器写了一个小库。切换到生产环境suds现在出现错误suds.TypeNotFound:未找到类型:'userName'
不太确定在哪里寻找。
#output
C:\Python\python.exe C:/Users/Alex/PycharmProjects/APIClient/APIClient.py
Traceback (most recent call last):
File "C:/Users/Alex/PycharmProjects/APIClient/APIClient.py", line 93, in <module>
main()
File "C:/Users/Alex/PycharmProjects/APIClient/APIClient.py", line 13, in main
archerapi.start_session(username,instance,password)
File "C:/Users/Alex/PycharmProjects/APIClient/APIClient.py", line 51, in start_session
self.token = self.general_client.service.CreateUserSessionFromInstance(cusfi)
File "C:\Python\lib\site-packages\suds\client.py", line 559, in __call__
return client.invoke(args, kwargs)
File "C:\Python\lib\site-packages\suds\client.py", line 612, in invoke
soapenv = binding.get_message(self.method, args, kwargs)
File "C:\Python\lib\site-packages\suds\bindings\binding.py", line 120, in get_message
content = self.bodycontent(method, args, kwargs)
File "C:\Python\lib\site-packages\suds\bindings\document.py", line 64, in bodycontent
p = self.mkparam(method, pd, value)
File "C:\Python\lib\site-packages\suds\bindings\document.py", line 106, in mkparam
return Binding.mkparam(self, method, pdef, object)
File "C:\Python\lib\site-packages\suds\bindings\binding.py", line 289, in mkparam
return marshaller.process(content)
File "C:\Python\lib\site-packages\suds\mx\core.py", line 60, in process
self.append(document, content)
File "C:\Python\lib\site-packages\suds\mx\core.py", line 73, in append
self.appender.append(parent, content)
File "C:\Python\lib\site-packages\suds\mx\appender.py", line 102, in append
appender.append(parent, content)
File "C:\Python\lib\site-packages\suds\mx\appender.py", line 243, in append
Appender.append(self, child, cont)
File "C:\Python\lib\site-packages\suds\mx\appender.py", line 182, in append
self.marshaller.append(parent, content)
File "C:\Python\lib\site-packages\suds\mx\core.py", line 72, in append
if self.start(content):
File "C:\Python\lib\site-packages\suds\mx\literal.py", line 87, in start
raise TypeNotFound(content.tag)
suds.TypeNotFound: Type not found: 'userName'
客户代码
#APIClient.py
from csv import writer
from suds import Client
import untangle
def main():
url = "https://egrcb-eur.archer.rsa.com"
username = ""
instance = ""
password = ""
archerapi = ArcherApi(url)
archerapi.start_session(username,instance,password)
archerapi.terminate_session()
class ArcherApi:
GENERAL_SUFFIX = "/ws/general.asmx?wsdl"
SEARCH_SUFFIX = "/ws/search.asmx?wsdl"
token = ""
def __init__(self,url):
self.general_client = Client(url + self.GENERAL_SUFFIX)
self.search_client = Client(url + self.SEARCH_SUFFIX)
def start_session(self, username, instance, password):
cusfi = self.general_client.factory.create("CreateUserSessionFromInstance")
cusfi.userName = username
cusfi.instanceName = instance
cusfi.password = password
self.token = self.general_client.service.CreateUserSessionFromInstance(cusfi)
print("Session Created token="+self.token)
def terminate_session(self):
return self.general_client.service.TerminateSession(self.token)
if __name__ == '__main__':
main()
WSDL
<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://archer-tech.com/webservices/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://archer-tech.com/webservices/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://archer-tech.com/webservices/">
<s:element name="CreateUserSession">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="userName" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="companyId" type="s:int"/>
<s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="CreateUserSessionResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="CreateUserSessionResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="CreateDomainUserSession">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="userName" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="companyId" type="s:int"/>
<s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="usersDomain" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="CreateDomainUserSessionResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="CreateDomainUserSessionResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="CreateUserSessionFromInstance">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="userName" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="instanceName" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="CreateUserSessionFromInstanceResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="CreateUserSessionFromInstanceResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="CreateDomainUserSessionFromInstance">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="userName" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="instanceName" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="usersDomain" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="CreateDomainUserSessionFromInstanceResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="CreateDomainUserSessionFromInstanceResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="TerminateSession">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="sessionToken" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="TerminateSessionResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="TerminateSessionResult" type="s:int"/>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="CreateUserSessionSoapIn">
<wsdl:part name="parameters" element="tns:CreateUserSession"/>
</wsdl:message>
<wsdl:message name="CreateUserSessionSoapOut">
<wsdl:part name="parameters" element="tns:CreateUserSessionResponse"/>
</wsdl:message>
<wsdl:message name="CreateDomainUserSessionSoapIn">
<wsdl:part name="parameters" element="tns:CreateDomainUserSession"/>
</wsdl:message>
<wsdl:message name="CreateDomainUserSessionSoapOut">
<wsdl:part name="parameters" element="tns:CreateDomainUserSessionResponse"/>
</wsdl:message>
<wsdl:message name="CreateUserSessionFromInstanceSoapIn">
<wsdl:part name="parameters" element="tns:CreateUserSessionFromInstance"/>
</wsdl:message>
<wsdl:message name="CreateUserSessionFromInstanceSoapOut">
<wsdl:part name="parameters" element="tns:CreateUserSessionFromInstanceResponse"/>
</wsdl:message>
<wsdl:message name="CreateDomainUserSessionFromInstanceSoapIn">
<wsdl:part name="parameters" element="tns:CreateDomainUserSessionFromInstance"/>
</wsdl:message>
<wsdl:message name="CreateDomainUserSessionFromInstanceSoapOut">
<wsdl:part name="parameters" element="tns:CreateDomainUserSessionFromInstanceResponse"/>
</wsdl:message>
<wsdl:message name="TerminateSessionSoapIn">
<wsdl:part name="parameters" element="tns:TerminateSession"/>
</wsdl:message>
<wsdl:message name="TerminateSessionSoapOut">
<wsdl:part name="parameters" element="tns:TerminateSessionResponse"/>
</wsdl:message>
<wsdl:portType name="generalSoap">
<wsdl:operation name="CreateUserSession">
<wsdl:input message="tns:CreateUserSessionSoapIn"/>
<wsdl:output message="tns:CreateUserSessionSoapOut"/>
</wsdl:operation>
<wsdl:operation name="CreateDomainUserSession">
<wsdl:input message="tns:CreateDomainUserSessionSoapIn"/>
<wsdl:output message="tns:CreateDomainUserSessionSoapOut"/>
</wsdl:operation>
<wsdl:operation name="CreateUserSessionFromInstance">
<wsdl:input message="tns:CreateUserSessionFromInstanceSoapIn"/>
<wsdl:output message="tns:CreateUserSessionFromInstanceSoapOut"/>
</wsdl:operation>
<wsdl:operation name="CreateDomainUserSessionFromInstance">
<wsdl:input message="tns:CreateDomainUserSessionFromInstanceSoapIn"/>
<wsdl:output message="tns:CreateDomainUserSessionFromInstanceSoapOut"/>
</wsdl:operation>
<wsdl:operation name="TerminateSession">
<wsdl:input message="tns:TerminateSessionSoapIn"/>
<wsdl:output message="tns:TerminateSessionSoapOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="generalSoap" type="tns:generalSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="CreateUserSession">
<soap:operation soapAction="http://archer-tech.com/webservices/CreateUserSession" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="CreateDomainUserSession">
<soap:operation soapAction="http://archer-tech.com/webservices/CreateDomainUserSession" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="CreateUserSessionFromInstance">
<soap:operation soapAction="http://archer-tech.com/webservices/CreateUserSessionFromInstance" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="CreateDomainUserSessionFromInstance">
<soap:operation soapAction="http://archer-tech.com/webservices/CreateDomainUserSessionFromInstance" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="TerminateSession">
<soap:operation soapAction="http://archer-tech.com/webservices/TerminateSession" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="generalSoap12" type="tns:generalSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="CreateUserSession">
<soap12:operation soapAction="http://archer-tech.com/webservices/CreateUserSession" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="CreateDomainUserSession">
<soap12:operation soapAction="http://archer-tech.com/webservices/CreateDomainUserSession" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="CreateUserSessionFromInstance">
<soap12:operation soapAction="http://archer-tech.com/webservices/CreateUserSessionFromInstance" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="CreateDomainUserSessionFromInstance">
<soap12:operation soapAction="http://archer-tech.com/webservices/CreateDomainUserSessionFromInstance" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="TerminateSession">
<soap12:operation soapAction="http://archer-tech.com/webservices/TerminateSession" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="general">
<wsdl:port name="generalSoap" binding="tns:generalSoap">
<soap:address location="https://egrcb-eur.archer.rsa.com/ws/general.asmx"/>
</wsdl:port>
<wsdl:port name="generalSoap12" binding="tns:generalSoap12">
<soap12:address location="https://egrcb-eur.archer.rsa.com/ws/general.asmx"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
答案 0 :(得分:0)
亚历克斯,
我不是Python方面的专家,但我建议你更换一行
self.token = self.general_client.service.CreateUserSessionFromInstance(cusfi)
与
self.token = self.general_client.service.CreateUserSessionFormInstance(**cusfi)
我在这里找到了这个解决方案:link 我希望这适合你。
谢谢你,Stan。