如何输出 SUD 正在生成/接收的内容?

发布于 2024-10-07 07:04:53 字数 602 浏览 3 评论 0原文

我有以下代码:

from suds.client import Client
import logging

logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.transport').setLevel(logging.DEBUG)
logging.getLogger('suds.xsd.schema').setLevel(logging.DEBUG)
logging.getLogger('suds.wsdl').setLevel(logging.DEBUG)

SB_PRIVATE_ACCESS = {"PATH":"https://thisurl.com:443/services/",}

client = Client(SB_PRIVATE_ACCESS['PATH'])
print client

但我收到 500 个错误。我正在尝试将通过 SUD 生成和接收的 XML 发送给 wsdl 开发人员,但我不知道如何输出它?我一直在查看 SUD 的文档,但似乎找不到它:/有人知道如何输出发送和接收的原始 xml 吗?

I have the following code:

from suds.client import Client
import logging

logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.transport').setLevel(logging.DEBUG)
logging.getLogger('suds.xsd.schema').setLevel(logging.DEBUG)
logging.getLogger('suds.wsdl').setLevel(logging.DEBUG)

SB_PRIVATE_ACCESS = {"PATH":"https://thisurl.com:443/services/",}

client = Client(SB_PRIVATE_ACCESS['PATH'])
print client

but I am getting 500 errors. I am trying to send what XML is being generated and received through SUDs, to the wsdl developer, but I can't figure how to output it? I have been looking in the documentation of SUDs, but can't seem to find it :/ Does anyone know how to output the raw xml that is sent and received?

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

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

发布评论

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

评论(7

不羁少年 2024-10-14 07:04:53

SUDS 提供了一些方便的方法来做到这一点:

 client.last_sent()
 client.last_received()

这些应该可以满足您的需要。我用它们来记录错误。
Client 类的 Client 类的 API 文档 应该包含您需要的任何额外信息。

SUDS provides some convenience methods to do just that:

 client.last_sent()
 client.last_received()

These should provide you with what you need. I use them for error logging.
The API doc for Client class should have any extra info you need.

智商已欠费 2024-10-14 07:04:53

您可以使用 MessagePlugin 来执行此操作(这适用于较新的 Jurko 分支,其中 last_sent 和 last_received 已被删除)

from suds.plugin import MessagePlugin

class LogPlugin(MessagePlugin):
  def sending(self, context):
    print(str(context.envelope))
  def received(self, context):
    print(str(context.reply))

client = Client("http://localhost/wsdl.wsdl", plugins=[LogPlugin()])

You can use the MessagePlugin to do this (this will work on the newer Jurko fork where last_sent and last_received have been removed)

from suds.plugin import MessagePlugin

class LogPlugin(MessagePlugin):
  def sending(self, context):
    print(str(context.envelope))
  def received(self, context):
    print(str(context.reply))

client = Client("http://localhost/wsdl.wsdl", plugins=[LogPlugin()])
谁的新欢旧爱 2024-10-14 07:04:53

Suds 支持内部日志记录,就像您一直在做的那样。

我像你一样设置信息级别:

logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.transport').setLevel(logging.DEBUG) # MUST BE THIS?
logging.getLogger('suds.xsd.schema').setLevel(logging.DEBUG)
logging.getLogger('suds.wsdl').setLevel(logging.DEBUG)
logging.getLogger('suds.resolver').setLevel(logging.DEBUG)
logging.getLogger('suds.xsd.query').setLevel(logging.DEBUG)
logging.getLogger('suds.xsd.basic').setLevel(logging.DEBUG)
logging.getLogger('suds.binding.marshaller').setLevel(logging.DEBUG)

有时我还需要覆盖根记录器日志记录级别,具体取决于 Suds 调用下使用的框架(Django、Plone)。如果根记录器具有更高的日志记录阈值,则日志消息可能永远不会出现(不确定记录器层次结构应该如何发展)。下面是如何覆盖的示例:

def enableDebugLog(self):
    """ Enable context.plone_log() output from Python scripts """
    import sys, logging
    logger = logging.getLogger()        
    logger.root.setLevel(logging.DEBUG)
    logger.root.addHandler(logging.StreamHandler(sys.stdout))

Suds supports internal logging, as you have been doing.

I am setting info levels like you:

logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.transport').setLevel(logging.DEBUG) # MUST BE THIS?
logging.getLogger('suds.xsd.schema').setLevel(logging.DEBUG)
logging.getLogger('suds.wsdl').setLevel(logging.DEBUG)
logging.getLogger('suds.resolver').setLevel(logging.DEBUG)
logging.getLogger('suds.xsd.query').setLevel(logging.DEBUG)
logging.getLogger('suds.xsd.basic').setLevel(logging.DEBUG)
logging.getLogger('suds.binding.marshaller').setLevel(logging.DEBUG)

And I also sometimes need to override the root logger logging level, depending on the framework being used under Suds calls (Django, Plone). If the root logger has a higher logging threshold, log messaegs may never appear (not sure how logger hierarchies should go). Below is an example how to override:

def enableDebugLog(self):
    """ Enable context.plone_log() output from Python scripts """
    import sys, logging
    logger = logging.getLogger()        
    logger.root.setLevel(logging.DEBUG)
    logger.root.addHandler(logging.StreamHandler(sys.stdout))
苏辞 2024-10-14 07:04:53

要仅获取生成的消息,这也有效:

from suds.client import Client
import sys

SB_PRIVATE_ACCESS = {"PATH":"https://thisurl.com:443/services/",}

client = Client(SB_PRIVATE_ACCESS['PATH'])

client.set_options(nosend=True)

resp = ...<invoke client here>...

sys.stdout.buffer.write(resp.envelope)

To get only the generated message this also works:

from suds.client import Client
import sys

SB_PRIVATE_ACCESS = {"PATH":"https://thisurl.com:443/services/",}

client = Client(SB_PRIVATE_ACCESS['PATH'])

client.set_options(nosend=True)

resp = ...<invoke client here>...

sys.stdout.buffer.write(resp.envelope)
七堇年 2024-10-14 07:04:53

尝试更改

logging.basicConfig(level=logging.INFO)

logging.basicConfig(filename="/tmp/suds.log", level=logging.DEBUG)

try changing

logging.basicConfig(level=logging.INFO)

to

logging.basicConfig(filename="/tmp/suds.log", level=logging.DEBUG)
九八野马 2024-10-14 07:04:53

如果您想减少 jurko-suds 的日志记录

 logging.basicConfig(level=logging.INFO)

    logging.getLogger('suds.client').setLevel(logging.INFO)
    logging.getLogger('suds.transport').setLevel(logging.INFO) 
    logging.getLogger('suds.xsd.schema').setLevel(logging.INFO)
    logging.getLogger('suds.wsdl').setLevel(logging.INFO)
    logging.getLogger('suds.resolver').setLevel(logging.INFO)
    logging.getLogger('suds.xsd.query').setLevel(logging.INFO)
    logging.getLogger('suds.xsd.sxbasic').setLevel(logging.INFO)
    logging.getLogger('suds.xsd.sxbase').setLevel(logging.INFO)
    logging.getLogger('suds.metrics').setLevel(logging.INFO)
    logging.getLogger('suds.binding.marshaller').setLevel(logging.INFO)

If you want to reduce logging by jurko-suds

 logging.basicConfig(level=logging.INFO)

    logging.getLogger('suds.client').setLevel(logging.INFO)
    logging.getLogger('suds.transport').setLevel(logging.INFO) 
    logging.getLogger('suds.xsd.schema').setLevel(logging.INFO)
    logging.getLogger('suds.wsdl').setLevel(logging.INFO)
    logging.getLogger('suds.resolver').setLevel(logging.INFO)
    logging.getLogger('suds.xsd.query').setLevel(logging.INFO)
    logging.getLogger('suds.xsd.sxbasic').setLevel(logging.INFO)
    logging.getLogger('suds.xsd.sxbase').setLevel(logging.INFO)
    logging.getLogger('suds.metrics').setLevel(logging.INFO)
    logging.getLogger('suds.binding.marshaller').setLevel(logging.INFO)
孤星 2024-10-14 07:04:53

我在使用 bingads API 时遇到了这个问题,值得注意的是,顺序很重要,我必须导入日志记录,然后导入 suds 启动日志记录,然后导入 bingads,任何其他顺序,suds 的日志中没有输出任何内容。

因此,检查您的导入订单,并移动您的日志记录语句,它可能会解决您的问题。

I have hit this problem working with the bingads API, worth noting the order is important I had to import logging then import suds start the logging then import bingads, any other order and nothing was output in the logs from suds.

So check your import order, and move your logging statements and it may fix your issue.

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