我正在尝试使该服务器运行,但是我不断收到错误消息:

服务器:

import soaplib
from soaplib.core.service import rpc, DefinitionBase
from soaplib.core.model.primitive import String, Integer
from soaplib.core.server import wsgi
from soaplib.core.model.clazz import Array

class HelloWorldService(DefinitionBase):
    @soap(String,Integer,_returns=Array(String))
    def say_hello(self,name,times):
        results = []
        for i in range(0,times):
            results.append('Hello, %s'%name)
        return results

if __name__=='__main__':
    try:
        from wsgiref.simple_server import make_server
        soap_application = soaplib.core.Application([HelloWorldService], 'tns')
        wsgi_application = wsgi.Application(soap_application)
        server = make_server('localhost', 7789, wsgi_application)
        server.serve_forever()
    except ImportError:
        print "Error: example server code requires Python >= 2.5"


错误:

Traceback (most recent call last):
  File "C:/Users/User/Desktop/wsdlHelloWorld.py", line 8, in <module>
    class HelloWorldService(DefinitionBase):
  File "C:/Users/User/Desktop/wsdlHelloWorld.py", line 9, in HelloWorldService
    @soap(String,Integer,_returns=Array(String))
NameError: name 'soap' is not defined


我找到它的地方是This,所以我认为自己出了点问题,我之前曾尝试安装soaplib几次,并且由于lxml依赖vcvarsall.bat而将它们破坏了,但是我不认为这样会物...

更新资料

好了,我通过在soap导入(duh)中添加soaplib.core.service来使示例工作。所以...

from soaplib.core.service import rpc, DefinitionBase, soap


但是现在当我尝试使用suds客户端示例时,他们提供了此错误。

  File "C:\Python27\lib\urllib2.py", line 1174, in do_open
    raise URLError(err)
URLError: <urlopen error [Errno 10061] No connection could be made because the target machine actively refused it>


更新资料

nmap扫描显示端口7789上没有运行任何服务,这将导致urllib2引发10061错误。

最佳答案

将以下行添加到您的导入中

   from soaplib.core.service import soap


它应该可以正常工作;-)

安全套

关于python - soaplib hello world程序存在问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8089070/

10-10 10:29