soaplib Hello World 程序的问题
我正在尝试让这个服务器运行,但总是出现一个错误:
服务器:
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
我在这里找到了这个,所以我想可能是我这边出了问题。我之前尝试安装soaplib几次,但因为lxml依赖vcvarsall.bat,搞得一团糟,不过我觉得这应该没什么关系……
更新
好吧,我通过在我的soaplib.core.service
导入中添加soap
来让示例工作了(真是的)。所以……
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错误。
2 个回答
0
难道应该是:@soapmethod(String,Integer,_returns=Array(String))
吗?
2
在你的导入部分添加以下这一行
from soaplib.core.service import soap
这样就应该没问题了 ;-)
securedome