python用法 - plt title python
如何輸出SUD正在生成/接收的內容? (5)
我有以下代碼:
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?
SUDS提供了一些方便的方法:
client.last_sent()
client.last_received()
這些應該為您提供所需的一切。 我用它們進行錯誤記錄。 Client類的API文檔應該包含您需要的任何額外信息。
嘗試改變
logging.basicConfig(level=logging.INFO)
至
logging.basicConfig(filename="/tmp/suds.log", level=logging.DEBUG)
您可以使用MessagePlugin執行此操作(這將適用於已刪除last_sent和last_received的較新Jurko fork)
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()])
我使用bingads API遇到了這個問題,值得注意的是順序很重要我必須導入日誌記錄然後導入suds開始記錄然後導入bingads,任何其他順序並且沒有從suds輸出日誌。
因此,請檢查您的導入訂單,並移動您的日誌記錄,這可能會解決您的問題。
要僅獲取生成的消息,這也有效:
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)