python - 在 python spyne 服务器中打印出整个 SOAP 请求
问题描述
我有一个使用spyne
. 这是代码:
class myService(ServiceBase):
@rpc(Integer, String, _returns=String)
def my_method(ctx):
sys.stdout.write("Request for `myService`: {}\n".format(ctx))
return "0," + "".join(random.sample(string.hexdigits, 16))
application = Application(
[myService],
tns=NAMESPACE,
in_protocol=Soap11(validator="lxml"),
out_protocol=Soap11()
)
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
logging.getLogger("spyne.util").setLevel(logging.DEBUG)
wsgi_app = WsgiApplication(application)
server = make_server("0.0.0.0", 5555, wsgi_app)
server.serve_forever()
这是一个模拟真实服务的模拟器。我将它们与所需的客户端连接起来,但code 400, message Bad HTTP/0.9 request type
每个请求都会出错。由于我无权访问正在调用我的模拟服务器的客户端,因此我想在我的服务器中打印出接收到的请求。上面的代码不起作用(sys.stdout.write
)。
编辑1:
我改为sys.stdout
python logger
:
import logging
logger = logging.getLogger("spyne.util")
...
...
...
logger.info("Request for `myService`: {}\n".format(ctx))
但是没有打印任何内容,这次我遇到了以下错误:
code 400, message Bad request syntax
解决方案
以下应该做到这一点:
logging.getLogger('').setLevel(logging.DEBUG)
logging.getLogger('spyne.protocol').setLevel(logging.DEBUG)
logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
推荐阅读
- python - 使用 matplotlib 在我的 x 轴上绘制时间,但是它从 0 开始,而不是实际开始时间
- c# - 使用“如果 API 中已存在此内容”类型语句
- javascript - Rails 将日期对象传递给 javascript
- google-bigquery - 如何查看大查询表的创建表 DDL?
- ruby-on-rails - 创建按两个字段分组的折线图
- python - TwiML 在
标签 - amazon-web-services - 使用 boto2 从加密桶中获取对象?
- angular - 在Angular中禁用带有工具提示的Bootstrap 4按钮
- javascript - firebase + react,setState 似乎不会触发重新渲染
- java - 如何解决 maven EnforcedBytecodeVersion 失败?