HTTP(WSGI)+JsonDocument Spyne客户端中的异常

2024-10-01 07:41:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我用Spyne编程了一个服务器端服务。我想使用Spyne客户端代码,但如果没有异常,我就做不到。

服务器端代码类似于(我删除了导入和统一文件):

class NotificationsRPC(ServiceBase):
    @rpc(Uuid, DateTime, _returns=Integer)
    def new_player(ctx, player_uuid, birthday):
        # A lot of irrelevant code
        return 0

    @rpc(Uuid, _returns=Integer)
    def deleted_player(ctx, player_uuid):
        # A lot of irrelevant code
        return 0

    # Many other similar methods

radiante_app = Application(
    [NotificationsRPC],
    tns="radiante.rpc",
    in_protocol=JsonDocument(validator="soft"),
    out_protocol=JsonDocument()
)
wsgi_app = WsgiApplication(radiante_app)
server = make_server('127.0.0.1', 27182, wsgi_app)
server.serve_forever()

这段代码运行正常,我可以通过CURL向它发出请求(真正的代码是用uWSGI实现的,但在本例中,我使用的是python嵌入式WSGI服务器)。

问题出现在客户端代码中。它类似于(RadianteRPC与服务器端中的类相同,但是方法体中的pass

^{pr2}$

然后,当代码执行时,我会出现以下错误:

File "/vagrant/apps/radsync/signal_hooks/player.py", line 74, in _player_post_save
created
File "/home/vagrant/devenv/local/lib/python2.7/site-packages/spyne/client/http.py", line 64, in __call__
self.get_in_object(self.ctx)
File "/home/vagrant/devenv/local/lib/python2.7/site-packages/spyne/client/_base.py", line 144, in get_in_object
message=self.app.in_protocol.RESPONSE)
File "/home/vagrant/devenv/local/lib/python2.7/site-packages/spyne/protocol/dictdoc.py", line 278, in decompose_incoming_envelope
raise ValidationError("Need a dictionary with exactly one key "
ValidationError: Fault(Client.ValidationError: 'The value "\'Need a dictionary with exactly one key as method name.\'" could not be validated.')

值得注意的是,客户机是用Django U\U实现的(不是我的决定),但我认为它与问题没有关系。

我遵循了这个问题的一些指示(将ZeroMQ传输协议的示例调整为HTTP传输协议):There is an example of Spyne client?

谢谢你的关注。


Tags: of代码inpyappline服务器端rpc