1

我已经使用 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 与服务器端的类相同,但在方法主体中传递:

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 传输协议):有一个 Spyne 客户端的示例?

感谢您的关注。

4

0 回答 0