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