我尝试运行spyne example。这个示例适用于Linux,但在Windows上会出现以下错误 -
File "helloWorld.py", line 14, in <module>
class HelloWorldService(ServiceBase):
File "helloWorld.py", line 15, in HelloWorldService
@srpc(Unicode, Integer, _returns=Iterable(Unicode))
NameError: name 'srpc' is not defined
有没有人有解决方案?
答案 0 :(得分:0)
那个例子是错的。这是正确的版本:
import logging
logging.basicConfig(level=logging.DEBUG)
from spyne import Application, rpc, ServiceBase, \
Integer, Unicode
from spyne import Iterable
from spyne.protocol.http import HttpRpc
from spyne.protocol.json import JsonDocument
from spyne.server.wsgi import WsgiApplication
class HelloWorldService(ServiceBase):
@rpc(Unicode, Integer, _returns=Iterable(Unicode))
def say_hello(ctx, name, times):
for i in range(times):
yield 'Hello, %s' % name
application = Application([HelloWorldService],
tns='spyne.examples.hello',
in_protocol=HttpRpc(validator='soft'),
out_protocol=JsonDocument()
)
if __name__ == '__main__':
# You can use any Wsgi server. Here, we chose
# Python's built-in wsgi server but you're not
# supposed to use it in production.
from wsgiref.simple_server import make_server
wsgi_app = WsgiApplication(application)
server = make_server('0.0.0.0', 8000, wsgi_app)
server.serve_forever()
我还修改了http://spyne.io上的代码。对此感到抱歉,非常感谢您将此问题引起我的注意。