2016-10-10 54 views
0

我試着運行一個spyne example。同樣的例子在Linux上運行,但在Windows上出現以下錯誤 -在Windows上運行spyne示例時出錯

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

這個例子是錯誤的。這是正確的版本:

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。對此感到抱歉,並非常感謝讓我注意到這個問題。

+0

謝謝。這工作。 – Ashutosh

相關問題