Python Spyne+Twisted SOAP服务器出现405错误

Python Spyne+Twisted SOAP服务器出现405错误,python,soap,twisted,spyne,Python,Soap,Twisted,Spyne,我试图用Spyne+Twisted实现一个python SOAP服务器 下面是示例服务器代码 import logging logging.basicConfig(level=logging.DEBUG) from spyne.application import Application from spyne.decorator import srpc from spyne.service import ServiceBase from spyne.model.primitive import

我试图用Spyne+Twisted实现一个python SOAP服务器

下面是示例服务器代码

import logging
logging.basicConfig(level=logging.DEBUG)
from spyne.application import Application
from spyne.decorator import srpc
from spyne.service import ServiceBase
from spyne.model.primitive import Integer
from spyne.model.primitive import Unicode
from spyne.model.complex import Iterable
from spyne.protocol.soap import Soap11
from spyne.server.twisted import TwistedWebResource
from twisted.internet import reactor
from twisted.web.server import Site


class HelloWorldService(ServiceBase):
    @srpc(Unicode, Integer, _returns=Iterable(Unicode))
    def say_hello(name, times):
        for i in range(times):
            yield 'Hello, %s' % name


application = Application([HelloWorldService],
                          tns='spyne.examples.hello',
                          in_protocol=Soap11(),
                          out_protocol=Soap11()
                          )

if __name__ == '__main__':
    resource = TwistedWebResource(application)
    site = Site(resource)
    reactor.listenTCP(8000, site, interface='0.0.0.0')
    reactor.run()
很简单

以下是客户端代码:

from pysimplesoap.client import SoapClient
import sys

if __name__ == '__main__':
    client = SoapClient(wsdl="http://{0}:{1}/?WSDL".format(sys.argv[1], sys.argv[2]))
    response = client.add_job('black')
    print 'result is ', response['add_jobResult']
我使用pythonclient.pylocalhost 8000运行客户机

以下是客户给我的:

No handlers could be found for logger "pysimplesoap.simplexml"
Traceback (most recent call last):
  File "client.py", line 22, in <module>
    client = SoapClient(wsdl="http://{0}:{1}/?WSDL".format(sys.argv[1], sys.argv[2]))
  File "/usr/local/lib/python2.7/dist-packages/PySimpleSOAP-1.10-py2.7.egg/pysimplesoap/client.py", line 133, in __init__
    self.services = wsdl and self.wsdl_parse(wsdl, cache=cache)
  File "/usr/local/lib/python2.7/dist-packages/PySimpleSOAP-1.10-py2.7.egg/pysimplesoap/client.py", line 471, in wsdl_parse
    wsdl = SimpleXMLElement(xml, namespace=wsdl_uri)
  File "/usr/local/lib/python2.7/dist-packages/PySimpleSOAP-1.10-py2.7.egg/pysimplesoap/simplexml.py", line 196, in __init__
    self.__document = xml.dom.minidom.parseString(text)
  File "/usr/lib/python2.7/xml/dom/minidom.py", line 1931, in parseString
    return expatbuilder.parseString(string)
  File "/usr/lib/python2.7/xml/dom/expatbuilder.py", line 940, in parseString
    return builder.parseString(string)
  File "/usr/lib/python2.7/xml/dom/expatbuilder.py", line 223, in parseString
    parser.Parse(string, True)
xml.parsers.expat.ExpatError: syntax error: line 1, column 0
现在,我该怎么办? 提前谢谢

更新: 浏览到?wsdl后,请注意小写405错误消失了,但之后我得到的结果是:

wsdl位区分大小写

http://localhost:8000/?wsdl 应该有用


浏览到http://localhost:8000/ 表示向发出GET请求http://localhost:8000/ 这在通过HTTP执行SOAP时是禁止的-SOAP端点只接受POST请求,因此405。

这可能是soaplib错误

我还遇到了以下问题: http://localhost:8000/?wsdl 可以 http://localhost:8000/?WSDL 将出现405错误

我修改了我的soaplib wsgi.py来修复这个问题/usr/local/lib/python2.7/dist-packages/soaplib-2.0.0b2-py2.7.egg/soaplib/core/server/wsgi.py

修改内容如下:

req_env['QUERY_STRING'].endswith('wsdl') or req_env['PATH_INFO'].endswith('wsdl')  or req_env['QUERY_STRING'].endswith('WSDL') or req_env['PATH_INFO'].endswith('WSDL')

甚至浏览到http://localhost:8000/ 顺便说一句,为什么不使用suds?suds,python soap客户端库。谢谢!它成功了,但又发生了一个错误。我更新了这个问题。好的,我刚刚发布了2.10.10,应该可以解决这个问题。请确认。
req_env['QUERY_STRING'].endswith('wsdl') or req_env['PATH_INFO'].endswith('wsdl')  or req_env['QUERY_STRING'].endswith('WSDL') or req_env['PATH_INFO'].endswith('WSDL')