Spyne - 具有多个目标命名空间的多个服务,使用 WsgiMounter 返回 404

发布于 2025-01-20 13:18:24 字数 2424 浏览 4 评论 0原文

我有两个服务,它们是一个应用程序的一部分,HelloAuth,并且每个服务都有自己的目标命名空间,如下所示:

from spyne import (
    Application, ServiceBase, rpc,
    Unicode,
)
from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication
from spyne.util.wsgi_wrapper import WsgiMounter
from wsgiref.simple_server import make_server
import logging


class Hello(ServiceBase):
    @rpc(_returns=Unicode)
    def hello(ctx):
        return "Hello, World!"

class Auth(ServiceBase):
    @rpc(_returns=Unicode)
    def authenticate(ctx):
        return "authenticated!"

我可以看到这些服务中的每一个都可以单独正常工作,如下所示:

hello = Application(
    [Hello],
    tns="hello_tns",
    name="hello",
    in_protocol=Soap11(validator="lxml"),
    out_protocol=Soap11(),
)

auth = Application(
    [Auth],
    tns="auth_tns",
    name="auth",
    in_protocol=Soap11(validator="lxml"),
    out_protocol=Soap11(),
)

hello_app = WsgiApplication(hello)
auth_app = WsgiApplication(auth)


if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    logging.getLogger("spyne.protocol.xml").setLevel(logging.DEBUG)

    server = make_server("0.0.0.0", 8000, hello_app)
    # server = make_server("0.0.0.0", 8000, auth_app)
    server.serve_forever()

我可以在 http://0.0.0.0:8000/?wsdl 中看到 wsdl >。

但我想将它们作为一个应用程序的一部分一起使用。

GitHub 上的此问题这个接受的答案,有人提到我应该创建两个实例spyne.Application 并使用 spyne.util.wsgi_wrapper.WsgiMounter 将它们放在一起。所以我也做了同样的事情:

wsgi_mounter = WsgiMounter({
    "hello": hello,
    "auth": auth,
})

if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    logging.getLogger("spyne.protocol.xml").setLevel(logging.DEBUG)

    server = make_server("0.0.0.0", 8000, wsgi_mounter)
    server.serve_forever()

但是现在当我查看 http://0.0.0.0:8000/?wsdl 时,我什么也没看到。服务器代码给我一个 404 错误响应:

$ python server.py
127.0.0.1 - - [09/Apr/2022 12:52:22] "GET /?wsdl HTTP/1.1" 404 0

我该如何解决这个问题?

I have two services that are part of one application, Hello and Auth, and each has its own target namespace, as such:

from spyne import (
    Application, ServiceBase, rpc,
    Unicode,
)
from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication
from spyne.util.wsgi_wrapper import WsgiMounter
from wsgiref.simple_server import make_server
import logging


class Hello(ServiceBase):
    @rpc(_returns=Unicode)
    def hello(ctx):
        return "Hello, World!"

class Auth(ServiceBase):
    @rpc(_returns=Unicode)
    def authenticate(ctx):
        return "authenticated!"

I can see that each of these services work fine individually, like this:

hello = Application(
    [Hello],
    tns="hello_tns",
    name="hello",
    in_protocol=Soap11(validator="lxml"),
    out_protocol=Soap11(),
)

auth = Application(
    [Auth],
    tns="auth_tns",
    name="auth",
    in_protocol=Soap11(validator="lxml"),
    out_protocol=Soap11(),
)

hello_app = WsgiApplication(hello)
auth_app = WsgiApplication(auth)


if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    logging.getLogger("spyne.protocol.xml").setLevel(logging.DEBUG)

    server = make_server("0.0.0.0", 8000, hello_app)
    # server = make_server("0.0.0.0", 8000, auth_app)
    server.serve_forever()

I can see the wsdl in http://0.0.0.0:8000/?wsdl.

But I want to use them together as part of one application.

In this issue on GitHub and this accepted answer, it's been mentioned that I should create two instances of spyne.Application and use spyne.util.wsgi_wrapper.WsgiMounter to put them together. So I did the same:

wsgi_mounter = WsgiMounter({
    "hello": hello,
    "auth": auth,
})

if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    logging.getLogger("spyne.protocol.xml").setLevel(logging.DEBUG)

    server = make_server("0.0.0.0", 8000, wsgi_mounter)
    server.serve_forever()

But now when I look at http://0.0.0.0:8000/?wsdl, I see nothing. And the server code gives me a 404 error response:

$ python server.py
127.0.0.1 - - [09/Apr/2022 12:52:22] "GET /?wsdl HTTP/1.1" 404 0

How can I fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

捶死心动 2025-01-27 13:18:24

好的,首先,这是一个很好的书面问题!谢谢!

如果您希望在同一应用下两种服务,请将它们传递到同一应用程序:

hello = Application(
    [Hello, Auth],
    tns="hello_tns",
    name="hello",
    in_protocol=Soap11(validator="lxml"),
    out_protocol=Soap11(),
)

使用HTTP时,在同一URL下不能使用多个应用程序。

如果您需要在不同的URL下(WSGimounter的用例)下的服务,则必须像以前一样:

wsgi_mounter = WsgiMounter({
    "hello": hello,
    "auth": auth,
})

但是您会在其各自的URL下找到您的应用程序:

  • http:// localhost:8000/hello/?wsdl
  • http:// localhost:// localhost: 8000/auth/?wsdl

Okay first, what a nicely written question! Thanks!

If you want both services under the same app, pass them to the same app:

hello = Application(
    [Hello, Auth],
    tns="hello_tns",
    name="hello",
    in_protocol=Soap11(validator="lxml"),
    out_protocol=Soap11(),
)

When using HTTP, you can't use more than one app under the same URL.

If you want services under different URLs (which is WsgiMounter's use case) you must do like you did:

wsgi_mounter = WsgiMounter({
    "hello": hello,
    "auth": auth,
})

but you will find your apps under their respective URLs:

  • http://localhost:8000/hello/?wsdl
  • http://localhost:8000/auth/?wsdl
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文