Spyne - 具有多个目标命名空间的多个服务,使用 WsgiMounter 返回 404
我有两个服务,它们是一个应用程序的一部分,Hello
和 Auth
,并且每个服务都有自己的目标命名空间,如下所示:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,首先,这是一个很好的书面问题!谢谢!
如果您希望在同一应用下两种服务,请将它们传递到同一应用程序:
使用HTTP时,在同一URL下不能使用多个应用程序。
如果您需要在不同的URL下(WSGimounter的用例)下的服务,则必须像以前一样:
但是您会在其各自的URL下找到您的应用程序:
Okay first, what a nicely written question! Thanks!
If you want both services under the same app, pass them to the same app:
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:
but you will find your apps under their respective URLs: