How can I output what SUDs is generating/receiving?

前端 未结 7 1808
甜味超标
甜味超标 2020-12-01 07:02

I have the following code:

from suds.client import Client
import logging

logging.basicConfig(level=logging.INFO)
logging.getLogger(\'suds.client\').setLevel         


        
相关标签:
7条回答
  • 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))
    
    0 讨论(0)
  • 2020-12-01 07:49

    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.

    0 讨论(0)
  • 2020-12-01 08:00

    try changing

    logging.basicConfig(level=logging.INFO)
    

    to

    logging.basicConfig(filename="/tmp/suds.log", level=logging.DEBUG)
    
    0 讨论(0)
  • 2020-12-01 08:00

    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)
    
    0 讨论(0)
  • 2020-12-01 08:01

    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)
    
    0 讨论(0)
  • 2020-12-01 08:03

    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.

    0 讨论(0)
提交回复
热议问题