spyne
spyne copied to clipboard
Error on MessagePackRpc, JsonRpc, MessagePackDocument & Json
Hello,
I tried to use the MessagePackRpc protocol but I got some errors. Then I tried JsonRpc, MessagePackDocument & Json and I got similar erros as well. Did I missed something ? I managed to make the code working by changing some stuff on the protocol/msgpack.py file but before to go any further I would like to know if this is me or there is a bug on these class.
(I changed the ctx.out_document = [[MessagePackRpc.MSGPACK_RESPONSE, 0, None
to make it work, I replaced None
by the name of the method and I replaced MSGPACK_RESPONSE
by MSGPACK_REQUEST
when needed)
app.py
from spyne.application import Application
from spyne.decorator import srpc
from spyne.service import ServiceBase
from spyne.model.complex import Iterable, ComplexModel
from spyne.model.primitive import UnsignedInteger
from spyne.model.primitive import String
from spyne.server.wsgi import WsgiApplication
from spyne.protocol.soap.soap11 import Soap11
from spyne.protocol.msgpack import MessagePackRpc, MessagePackDocument
from spyne.protocol.json import JsonRpc, JsonDocument
class MyType(ComplexModel):
a = String
b = String
class HelloWorldService(ServiceBase):
@srpc(MyType, UnsignedInteger, _returns=Iterable(String))
def say_hello(name, times):
print(name)
for i in xrange(times):
yield 'Hello, %s' % (name.a + name.b)
app = Application([HelloWorldService], name='HelloWorldService', tns='my.ns.roxx',
in_protocol=MessagePackRpc(), out_protocol=MessagePackRpc(),
#in_protocol=JsonRpc('spyne'), out_protocol=JsonRpc('spyne'),
)
http_server.py
import logging
from wsgiref.simple_server import make_server
from spyne.server.wsgi import WsgiApplication
from app import app
if __name__=='__main__':
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
wsgi_app = WsgiApplication(app)
server = make_server('127.0.0.1', 7789, wsgi_app)
print "listening to http://127.0.0.1:7789"
print "wsdl is at: http://localhost:7789/?wsdl"
server.serve_forever()
http_client.py
import logging
from spyne.client.http import HttpClient
import app
client = HttpClient('http://127.0.0.1:7789', app.app)
t = app.MyType()
t.a = 'ca'
t.b = 'cao'
print list(client.service.say_hello(t, 5))
server output
$ python http_server.py
listening to http://127.0.0.1:7789
wsdl is at: http://localhost:7789/?wsdl
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/Users/thomas/dev/spyne/spyne/spyne/server/wsgi.py", line 232, in __call__
return self.handle_rpc(req_env, start_response)
File "/Users/thomas/dev/spyne/spyne/spyne/server/wsgi.py", line 335, in handle_rpc
contexts = self.generate_contexts(initial_ctx, in_string_charset)
File "/Users/thomas/dev/spyne/spyne/spyne/server/_base.py", line 66, in generate_contexts
ProtocolBase.REQUEST)
File "/Users/thomas/dev/spyne/spyne/spyne/protocol/msgpack.py", line 163, in decompose_incoming_envelope
assert message == MessagePackRpc.RESPONSE
AssertionError
127.0.0.1 - - [04/Jun/2014 17:23:48] "POST / HTTP/1.1" 500 59
client output
$ python http_client.py
Traceback (most recent call last):
File "http_client.py", line 13, in <module>
print list(client.service.say_hello(t, 5))
File "/Users/thomas/dev/spyne/spyne/spyne/client/http.py", line 64, in __call__
self.get_in_object(self.ctx)
File "/Users/thomas/dev/spyne/spyne/spyne/client/_base.py", line 137, in get_in_object
self.app.in_protocol.create_in_document(ctx)
File "/Users/thomas/dev/spyne/spyne/spyne/protocol/msgpack.py", line 136, in create_in_document
raise MessagePackDecodeError(''.join(e.args))
spyne.protocol.msgpack.MessagePackDecodeError: Fault(Client.MessagePackDecodeError: 'MessagePackDecodeError')
Does #360 fix your issues here? Should we close this?
#360 fixes the MessagePackRpc
protocol issue, there are still same kind of errors on JsonRpc
, MessagePackDocument
& Json
.
Spyne's client transports are unfortunately quite neglected. I'll focus on them once I get the wsdl parsing working.
As for the issues with protocol, they should work, I'll have a look at them as soon as possible. In the mean time, don't hesitate to send other pull requests (especially with tests) it'll make my job easier.
The coverage reports should give a good idea about what needs testing.
https://spyne.ci.cloudbees.com/job/spyne/PYFLAV=2.7/73/cobertura/default/
I took a quick look but couldn't find what's wrong with the other protocols. This bug is rendering the library pretty much unusable for me :(
you need to take a deeper look then, sadface.