Python WSDL客户端的身份验证问题

2024-09-29 01:39:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试连接到wsdl,在我弄清楚之前无法继续。在

from suds.client import Client

client = Client('<https_wsdl_url>')

print(client)

kwargs = {'username': '<username>', 'password': '<password>', 'type': '',}
response = client.service.Login(**kwargs)

print(response)

打印客户端表明可以使用以下方法调用该方法:

^{pr2}$

我收到一个错误的身份验证错误,即使身份验证在soapUI中有效。stacktrace是:

No handlers could be found for logger "suds.client"
Traceback (most recent call last):
  File "C:/test.py", line 16, in <module>
    response = client.service.Login(**kwargs)
  File "C:\Python27\lib\site-packages\suds\client.py", line 542, in __call__
    return client.invoke(args, kwargs)
  File "C:\Python27\lib\site-packages\suds\client.py", line 602, in invoke
    result = self.send(soapenv)
  File "C:\Python27\lib\site-packages\suds\client.py", line 649, in send
    result = self.failed(binding, e)
  File "C:\Python27\lib\site-packages\suds\client.py", line 702, in failed
    r, p = binding.get_fault(reply)
  File "C:\Python27\lib\site-packages\suds\bindings\binding.py", line 265, in get_fault
    raise WebFault(p, faultroot)
suds.WebFault: Server raised fault: 'bad authentication'

完整跟踪:

DEBUG:suds.xsd.query:(u'Login', u'<URL>'), found as: <Element:0x2b6ebf0 name="Login" />
DEBUG:suds.xsd.query:(u'Login', u'<URL>'), found as: <Element:0x2b6ebf0 name="Login" />
DEBUG:suds.mx.core:processing:
(Content){
   tag = "username"
   value = "<USERNAME>"
   real = <XString:0x3b95690 />
   type = <Element:0x2b6eb70 name="username" type="(u'string', u'http://www.w3.org/2001/XMLSchema')" />
 }
Traceback (most recent call last):
  File "C:\Python27\lib\logging\__init__.py", line 861, in emit
    msg = self.format(record)
  File "C:\Python27\lib\logging\__init__.py", line 734, in format
    return fmt.format(record)
  File "C:\Python27\lib\logging\__init__.py", line 465, in format
    record.message = record.getMessage()
  File "C:\Python27\lib\logging\__init__.py", line 329, in getMessage
    msg = msg % self.args
  File "C:\Python27\lib\site-packages\suds\sax\document.py", line 58, in __str__
    return unicode(self).encode('utf-8')
  File "C:\Python27\lib\site-packages\suds\sax\document.py", line 61, in __unicode__
    return self.str()
  File "C:\Python27\lib\site-packages\suds\sax\document.py", line 48, in str
    s.append(self.root().str())
AttributeError: 'NoneType' object has no attribute 'str'
Logged from file core.py, line 73
DEBUG:suds.mx.literal:starting content:
(Content){
   tag = "username"
   value = "<USERNAME>"
   real = <XString:0x3b956760 />
   type = <Element:0x2b6eb70 name="username" type="(u'string', u'http://www.w3.org/2001/XMLSchema')" />
 }
DEBUG:suds.resolver:push: (<suds.resolver.Frame instance at 0x02BD78C8>)
<suds.resolver.Frame instance at 0x02BD78C8>
DEBUG:suds.mx.literal:created - node:
<tns:username xmlns:tns="<URL>"/>
DEBUG:suds.mx.literal:ending content:
(Content){
   tag = "username"
   value = "<USERNAME>"
   real = <XString:0x3b95760 />
   type = <Element:0x2b6eb70 name="username" type="(u'string', u'http://www.w3.org/2001/XMLSchema')" />
   ancestry[] = <empty>
 }
DEBUG:suds.resolver:pop: (<suds.resolver.Frame instance at 0x02BD78C8>)

DEBUG:suds.mx.core:processing:
(Content){
   tag = "password"
   value = "<PASSWORD>"
   real = <XString:0x3b95745/>
   type = <Element:0x2b6ead0 name="password" type="(u'string', u'http://www.w3.org/2001/XMLSchema')" />
 }
Traceback (most recent call last):
  File "C:\Python27\lib\logging\__init__.py", line 861, in emit
    msg = self.format(record)
  File "C:\Python27\lib\logging\__init__.py", line 734, in format
    return fmt.format(record)
  File "C:\Python27\lib\logging\__init__.py", line 465, in format
    record.message = record.getMessage()
  File "C:\Python27\lib\logging\__init__.py", line 329, in getMessage
    msg = msg % self.args
  File "C:\Python27\lib\site-packages\suds\sax\document.py", line 58, in __str__
    return unicode(self).encode('utf-8')
  File "C:\Python27\lib\site-packages\suds\sax\document.py", line 61, in __unicode__
    return self.str()
  File "C:\Python27\lib\site-packages\suds\sax\document.py", line 48, in str
    s.append(self.root().str())
AttributeError: 'NoneType' object has no attribute 'str'
Logged from file core.py, line 73
DEBUG:suds.mx.literal:starting content:
(Content){
   tag = "password"
   value = "<PASSWORD>"
   real = <XString:0x3b95745 />
   type = <Element:0x2b6ead0 name="password" type="(u'string', u'http://www.w3.org/2001/XMLSchema')" />
 }
DEBUG:suds.resolver:push: (<suds.resolver.Frame instance at 0x03AFBBC0>)
<suds.resolver.Frame instance at 0x03AFBBC0>
DEBUG:suds.mx.literal:created - node:
<tns:password xmlns:tns="<URL>"/>
DEBUG:suds.mx.literal:ending content:
(Content){
   tag = "password"
   value = "<PASSWORD>"
   real = <XString:0x3b95745 />
   type = <Element:0x2b6ead0 name="password" type="(u'string', u'http://www.w3.org/2001/XMLSchema')" />
   ancestry[] = <empty>
 }
DEBUG:suds.resolver:pop: (<suds.resolver.Frame instance at 0x03AFBBC0>)

DEBUG:suds.mx.core:processing:
(Content){
   tag = "source"
   value = ""
   real = <XString:0x3b956d0 />
   type = <Element:0x2b6e970 name="source" type="(u'string', u'http://www.w3.org/2001/XMLSchema')" />
 }
Traceback (most recent call last):
  File "C:\Python27\lib\logging\__init__.py", line 861, in emit
    msg = self.format(record)
  File "C:\Python27\lib\logging\__init__.py", line 734, in format
    return fmt.format(record)
  File "C:\Python27\lib\logging\__init__.py", line 465, in format
    record.message = record.getMessage()
  File "C:\Python27\lib\logging\__init__.py", line 329, in getMessage
    msg = msg % self.args
  File "C:\Python27\lib\site-packages\suds\sax\document.py", line 58, in __str__
    return unicode(self).encode('utf-8')
  File "C:\Python27\lib\site-packages\suds\sax\document.py", line 61, in __unicode__
    return self.str()
  File "C:\Python27\lib\site-packages\suds\sax\document.py", line 48, in str
    s.append(self.root().str())
AttributeError: 'NoneType' object has no attribute 'str'
Logged from file core.py, line 73
DEBUG:suds.mx.literal:starting content:
(Content){
   tag = "source"
   value = ""
   real = <XString:0x3b956d0 />
   type = <Element:0x2b6e970 name="source" type="(u'string', u'http://www.w3.org/2001/XMLSchema')" />
 }
DEBUG:suds.resolver:push: (<suds.resolver.Frame instance at 0x03B64AA8>)
<suds.resolver.Frame instance at 0x03B64AA8>
DEBUG:suds.mx.literal:created - node:
<tns:source xmlns:tns="<URL>"/>
DEBUG:suds.mx.literal:ending content:
(Content){
   tag = "source"
   value = ""
   real = <XString:0x3b956d0 />
   type = <Element:0x2b6e970 name="source" type="(u'string', u'http://www.w3.org/2001/XMLSchema')" />
   ancestry[] = <empty>
 }
DEBUG:suds.resolver:pop: (<suds.resolver.Frame instance at 0x03B64AA8>)

DEBUG:suds.metrics:message for 'Login' created: 5 (ms)
DEBUG:suds.client:sending to (<HTTPS_ENDPOINT>)
message:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="<URL>" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <ns0:Body>
      <ns1:Login>
         <ns1:username><USERNAME></ns1:username>
         <ns1:password><PASSWORD></ns1:password>
         <ns1:source></ns1:source>
      </ns1:Login>
   </ns0:Body>
</SOAP-ENV:Envelope>
DEBUG:suds.client:headers = {'SOAPAction': u'"<URL>/Login"', 'Content-Type': 'text/xml; charset=utf-8'}
DEBUG:suds.transport.http:sending:
URL:<HTTPS_ENDPOINT>
HEADERS: {'SOAPAction': u'"<URL>/Login"', 'Content-Type': 'text/xml; charset=utf-8', 'Content-type': 'text/xml; charset=utf-8', 'Soapaction': u'"<URL>/Login"'}
MESSAGE:
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="<URL>" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><ns0:Body><ns1:Login><ns1:username><USERNAME></ns1:username><ns1:password><PASSWORD></ns1:password><ns1:source></ns1:source></ns1:Login></ns0:Body></SOAP-ENV:Envelope>
ERROR:suds.client:<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="<URL>" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <ns0:Body>
      <ns1:Login>
         <ns1:username><USERNAME></ns1:username>
         <ns1:password><PASSWORD></ns1:password>
         <ns1:source></ns1:source>
      </ns1:Login>
   </ns0:Body>
</SOAP-ENV:Envelope>
DEBUG:suds.client:http failed:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>bad authentication</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope>
DEBUG:suds.metrics:<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>bad authentication</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope>
sax duration: 0 (ms)
Traceback (most recent call last):
  File "C:/GIT Repo/cpp-bdd-regression-tests/steps/test.py", line 17, in <module>
    response = client.service.Login(**kwargs)
  File "C:\Python27\lib\site-packages\suds\client.py", line 542, in __call__
    return client.invoke(args, kwargs)
  File "C:\Python27\lib\site-packages\suds\client.py", line 602, in invoke
    result = self.send(soapenv)
  File "C:\Python27\lib\site-packages\suds\client.py", line 649, in send
    result = self.failed(binding, e)
  File "C:\Python27\lib\site-packages\suds\client.py", line 702, in failed
    r, p = binding.get_fault(reply)
  File "C:\Python27\lib\site-packages\suds\bindings\binding.py", line 265, in get_fault
    raise WebFault(p, faultroot)
suds.WebFault: Server raised fault: 'bad authentication'

Process finished with exit code 1

Tags: inpyorgdebugclienthttplibtype