【问题标题】:Requested resource '{spyne.examples.django}' not found未找到请求的资源“{spyne.examples.django}”
【发布时间】:2019-10-30 09:19:44
【问题描述】:

我正在尝试使用 Spyne 在 Django 中开发一个肥皂服务。我在 Django 应用程序中为应用程序“Hello_world”克隆了 spyne,但出现错误。有人可以帮我吗?

我的代码类似于下面的代码:

app = Application([HelloWorldService], 'spyne.examples.hello.http',
    in_protocol=HttpRpc(),
    out_protocol=Soap11(),
)

但出现以下错误:

<faultcode>soap11env:Client.ResourceNotFound</faultcode>
<faultstring>Requested resource '{spyne.examples.django}' not found</faultstring>
<faultactor/>

【问题讨论】:

    标签: django spyne


    【解决方案1】:

    没有为根 url 定义处理程序:

    https://github.com/plq/spyne/blob/b3b3f198b6148a498cdaeda9897307e0c5b1aac1/examples/django/rpctest/urls.py#L40

    将输入协议切换为 HttpRpc 并执行以下操作后:

    curl -D - localhost:8000/hello_world/
    

    你得到:

    <?xml version='1.0' encoding='UTF-8'?>
    <soap11env:Envelope xmlns:soap11env="http://schemas.xmlsoap.org/soap/envelope/">
    <soap11env:Body>
    <soap11env:Fault>
        <faultcode>soap11env:Client.ResourceNotFound</faultcode>
        <faultstring>Requested resource u'{spyne.examples.django}' not found</faultstring>
        <faultactor></faultactor>
    </soap11env:Fault>
    </soap11env:Body></soap11env:Envelope>
    

    那是因为你没有指定调用哪个方法。

    该示例中的HelloWorldService 定义了say_hello 函数。你可以这样称呼。

    curl -D - "localhost:8000/hello_world/say_hello"
    

    现在它找到了方法,但由于未验证的输入被传递给您的函数,您得到了一个回溯(我不会在此处包含)。

    如果传递所有参数:

    curl -D - "localhost:8000/hello_world/say_hello?times=5&name=Fatemeh"
    

    你得到:

        <?xml version='1.0' encoding='UTF-8'?>
        <soap11env:Envelope xmlns:soap11env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="spyne.examples.django">
        <soap11env:Body><tns:say_helloResponse>
        <tns:say_helloResult>
            <tns:string>Hello, Fatemeh</tns:string>
            <tns:string>Hello, Fatemeh</tns:string>
            <tns:string>Hello, Fatemeh</tns:string>
            <tns:string>Hello, Fatemeh</tns:string>
            <tns:string>Hello, Fatemeh</tns:string>
        </tns:say_helloResult></tns:say_helloResponse></soap11env:Body></soap11env:Envelope>
    

    您可能希望启用验证以避免Server 异常。首先我们在输入类型中添加Mandatory 标记:

        from spyne import M
        class HelloWorldService(Service):
            @rpc(M(Unicode), M(Integer), _returns=Iterable(Unicode))
            def say_hello(ctx, name, times):
                for i in range(times):
                    yield 'Hello, %s' % name
    

    然后我们启用软验证(HttpRpc 唯一的一个)

    app = Application([HelloWorldService], 'spyne.examples.hello.http',
        in_protocol=HttpRpc(validator='soft'),
        out_protocol=Soap11(),
    )
    

    服务器重启后如下:

    curl -D - "localhost:8000/hello_world/say_hello"
    

    你得到:

    <class 'spyne.model.complex.say_hello'>.name member must occur at least 1 times.
    

    我希望这会有所帮助!

    【讨论】:

      【解决方案2】:

      您可能还需要使用 in_protocol Soap11。

      from spyne.application import Application
      app = Application([HelloWorldService], 'spyne.examples.hello.http',
                  in_protocol=Soap11(validator='lxml'),
                  out_protocol=Soap11(),
              )
      

      你可以查看参考link

      【讨论】:

      • 谢谢,但我想用HttpRpc,我也不知道如何在django app上设置tns。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-06
      • 2014-04-13
      • 2017-06-28
      相关资源
      最近更新 更多