使用soappy SOAPServer时,如何读取请求的标头?
我有一个使用 SOAPpy 的 Python Web 服务。 Web 服务服务器的结构如下所示:
class myClass:
def hello():
return 'world'
if __name__ == "__main__":
server = SOAPServer( ( 'localhost', 8888 ) )
myObject = myClass()
namespace = 'whatever::namespace'
server.registerObject( myObject, namespace )
server.serve_forever()
如果客户端从我的 Web 服务调用 hello()
方法,我如何读取标头,以便我可以开始记录一些信息(例如:IP 地址)用于调试?
I've got a Python webservice using SOAPpy. The webservice server is structured as shown below:
class myClass:
def hello():
return 'world'
if __name__ == "__main__":
server = SOAPServer( ( 'localhost', 8888 ) )
myObject = myClass()
namespace = 'whatever::namespace'
server.registerObject( myObject, namespace )
server.serve_forever()
If a client calls the hello()
method from my webservice, how can I read the headers, so I can start logging some information (for example: ip address) for debugging?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想在您的 hello 方法中进行日志记录吗?下面是一个最小的示例,展示了如何将 SOAPContext 信息(可以为您提供一些此类信息)传递到函数/方法调用中:
Do you want to do the logging in your hello method? Here's a minimal example that shows how to pass the SOAPContext information (which can give you some of this info) into the function/method call:
您可以将
RequestHandler
添加到扩展SOAPRequestHandler
的 SoapServer 对象并替换HeaderHandler
(查看 server.py 为例)you can add a
RequestHandler
to the SoapServer object that extends theSOAPRequestHandler
and replaces theHeaderHandler
(have a look at the source of server.py for an example)