python調用SOA服務,運用suds模塊python
#! /usr/bin/python # coding:gbk import suds,time,sys reload(sys) sys.setdefaultencoding( "utf-8" ) import logging logging.basicConfig(level=logging.INFO, format='%(asctime)s %(filename)s[line:%(lineno)d] 【%(levelname)s】 %(message)s', datefmt='%a, %d %b %Y %H:%M:%S', filename=r".\Service"+time.strftime(r'%Y-%m-%d', time.localtime(time.time()))+".log", filemode='a') console = logging.StreamHandler() logging.getLogger('suds.client').addHandler(console) def TestService(): url='服務的WSDL連接地址' client = suds.client.Client(url) param1=dict(X='123') result1=client.service.METHODNAME1(param1) writeLog('METHODNAME1',result1) def writeLog(methodname,result): '''寫日誌''' content = methodname + "\n" for item in result: content=content+'\t|'+str(item) if result.Success==False: logging.error(content) else: logging.info(content) if __name__=="__main__": TestService()