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

时间:2014-08-19 10:52:14

标签: python spyne

我使用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

radiante_app = Application(
    [RadianteRPC],
    tns="radiante.rpc",
    in_protocol=JsonDocument(validator="soft"),
    out_protocol=JsonDocument()
)
rad_client = HttpClient("http://127.0.0.1:27182", radiante_app)

# In the real code, the parameters have more sense.
rad_client.service.new_player(uuid.UUID(), datetime.utcnow())

然后,当代码执行时,我有以下错误:

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?

感谢您的关注。

0 个答案:

没有答案