Windows 上的错误 运行 spyne 示例
Error running spyne example on Windows
我尝试了 运行 个 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
有人有解决办法吗??
那个例子是错误的。这是正确的版本:
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 上修复了代码。对此深表歉意,非常感谢您提请我注意这个问题。
我尝试了 运行 个 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
有人有解决办法吗??
那个例子是错误的。这是正确的版本:
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 上修复了代码。对此深表歉意,非常感谢您提请我注意这个问题。