Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 你能帮我解决这个肥皂水问题吗?_Python_Soap_Wsdl_Suds - Fatal编程技术网

Python 你能帮我解决这个肥皂水问题吗?

Python 你能帮我解决这个肥皂水问题吗?,python,soap,wsdl,suds,Python,Soap,Wsdl,Suds,所以我尝试使用sud访问这个api。以下是应该有效的代码: from suds.client import Client client = Client('https://www.clarityaccounting.com/api/v1?wsdl') token = client.service.doLogin('demo', 'demo', 'www.kashoo.com', 'en_US', 300000) 但我得到了这个错误: WebFault: Server raised fault:

所以我尝试使用sud访问这个api。以下是应该有效的代码:

from suds.client import Client
client = Client('https://www.clarityaccounting.com/api/v1?wsdl')
token = client.service.doLogin('demo', 'demo', 'www.kashoo.com', 'en_US', 300000)
但我得到了这个错误:

WebFault: Server raised fault: 'No such operation:  (HTTP GET PATH_INFO: /api/v1)'
他们的支持人员说请求应该是这样的:

<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:api="http://api.service.books/">
  <SOAP-ENV:Body>
     <api:doLogin>
        <username>demo</username>
        <password>demo</password>
        <siteName>www.kashoo.com</siteName>
        <locale>en_US</locale>
        <duration>300000</duration>
     </api:doLogin>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope 
xmlns:ns0="http://api.service.books/" 
xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <ns1:Body>
      <ns0:doLogin>
         <username>demo</username>
         <password>demo</password>
         <siteName>www.kashoo.com</siteName>
         <locale>en_US</locale>
         <duration>300000</duration>
      </ns0:doLogin>
   </ns1:Body>
</SOAP-ENV:Envelope>


因此,我的问题很简单,什么是不同的、导致请求失败的关键部分,以及如何配置sud来发送正确格式的请求?

乍一看,您遇到的问题似乎是SSL。您正在访问https URL,默认情况下,suds.client的传输处理程序会与http通信

问题
如果查看WSDL的底部,它将默认位置指定为
http://www.clarityaccounting.com/api/v1
,这是一个http URL,但WSDL是SSL

 <wsdl:service name="v1">
    <wsdl:port binding="tns:v1SoapBinding" name="BooksApiV1Port">
      <soap:address location="http://www.clarityaccounting.com/api/v1"/>
    </wsdl:port>
 </wsdl:service>
胜利

用于将来调试的Pro提示:启用完整日志调试。SUDS使用标准的
日志记录
库,因此它提供了大量的控制。因此,我将其全部设置为
DEBUG

import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.transport').setLevel(logging.DEBUG)
logging.getLogger('suds.xsd.schema').setLevel(logging.DEBUG)
logging.getLogger('suds.wsdl').setLevel(logging.DEBUG)
这就是帮助我缩小范围的原因,因为它清楚地表明它是通过http发送的:

DEBUG:suds.transport.http:sending:
URL:http://www.clarityaccounting.com/api/v1
(xml output omitted)
然后回应也这么说:

DEBUG:suds.client:http failed:

通过HTTPS连接到服务不应该是一个问题。我用肥皂水做同样的事情。我尝试了几种方法来处理您的WSDL文件(我自己不是专家),但遇到了相同的错误。不过,在练习使用肥皂水时,您应该使用工厂方法,例如:

login = client.factory.create('doLogin')
login.username = 'username'
etc...
其中,发送到create函数的任何内容都是WSDL文件中定义的类型之一。如果在shell中创建该类型,则可以运行“打印登录”以查看其其他属性

希望这至少能告诉您问题出在哪里(使用HTTPS)。另外,我注意到WSDL文件中没有设置soapAction头,因此不确定如果没有设置,SUD或服务如何处理请求。

使用SUD jurko,这是一种维护的SUD分支。 您可以传入一个uuu inject选项,在该选项中,您可以为它提供要发送的原始xml

from suds.client import Client

username, password, sitename, locale, duration = 'demo', 'demo', 'www.kashoo.com', 'en_US', 300000

raw_xml = """<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:api="http://api.service.books/">
  <SOAP-ENV:Body>
     <api:doLogin>
        <username>{0}</username>
        <password>{1}</password>
        <siteName>{2}</siteName>
        <locale>{3}</locale>
        <duration>{4}</duration>
     </api:doLogin>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>""".format(username, password, sitename, locale, duration)

client = Client(url, location)
result = client.service.doLogin(__inject={'msg':raw_xml})
从suds.client导入客户端
用户名、密码、网站名、区域设置、持续时间='demo','demo','www.kashoo.com','en_US',300000
原始xml=“”

正如您在我修改后的答案中所看到的,问题不在于通过https连接,而在于通过https提供的WSDL中存在不一致性,同时将SOAP调用指向http。我猜想,他们将服务配置为将传入URL从http重定向到https的方式是问题的根源。我们已经真正做到了很高兴能帮上忙!周五下午解决这个问题很有趣。谢谢!我只是在使用不同的web服务时遇到了相同的问题,但是遇到了相同的https/http问题。我找不到如何将客户端设置为使用https,即使WSDL说使用http。当人们托管web服务时,这是一个常见的问题ces通过HTTPS,但忘记相应地更新WSDL,或者不配置他们的服务器以正确地将HTTP重定向到HTTPS。我很高兴能够提供帮助!感谢suds修复了更多Microsoft的垃圾!
login = client.factory.create('doLogin')
login.username = 'username'
etc...
from suds.client import Client

username, password, sitename, locale, duration = 'demo', 'demo', 'www.kashoo.com', 'en_US', 300000

raw_xml = """<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:api="http://api.service.books/">
  <SOAP-ENV:Body>
     <api:doLogin>
        <username>{0}</username>
        <password>{1}</password>
        <siteName>{2}</siteName>
        <locale>{3}</locale>
        <duration>{4}</duration>
     </api:doLogin>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>""".format(username, password, sitename, locale, duration)

client = Client(url, location)
result = client.service.doLogin(__inject={'msg':raw_xml})