from suds.client import Client
import time
import hashlib
import sys,os
pa = "\\".join(os.path.split(os.path.realpath(__file__))[0].split('\\')[:-2])
sys.path.append(pa)
reload(sys)
sys.setdefaultencoding('utf-8')
def get_soapInfo(project, startTime, endTime):
client = Client("http://example.com/service.asmx?wsdl")
user = "user"
passwd = "passwd"
method = "method"
utcTime = time.strftime('%Y-%m-%dT%H:%M:%S')
hashStr = user+passwd+method+utcTime.replace("-","").replace("T","").replace(":","")
soapHeader = client.factory.create("ValidateHeader")
soapHeader.Hash = hashlib.md5(hashStr.encode("utf-8")).hexdigest().upper()
soapHeader.VisitorId = user
soapHeader.Method = method
soapHeader.UtcTime = utcTime
client.set_options(soapheaders=soapHeader)
parameters = client.factory.create("ArrayOfWsParameter")
tlist = [{"Name":"NameA","Value":project},{"Name":"STime","Value":startTime},{"Name":"ETime","Value":endTime}]
tlist.append({"Name":"PageIndex","Value":"1"})
tlist.append({"Name":"PageSize","Value":"500"})
tlist.append({"Name":"Fields","Value":"Field1,Field2"})
parameters.WsParameter = tlist
ret = client.service['ServiceSoap12'].GetPageListBy(parameters)
pageIndex = 1
while ret.PageCount > 0:
for item in ret.Values.ArrayOfAnyType:
thisItem = dict(zip(ret.Names.string,dts.anyType))
if thisItem["Field1"] == "Str1" :
print "Field2 " + thisItem["Field2"]
#other code
pageIndex += 1
if pageIndex > ret.PageCount:
break
tlist[3] = {"Name":"PageIndex","Value":str(pageIndex)}
parameters.WsParameter = tlist
ret = client.service['ServiceSoap12'].GetPageListBy(parameters)
today = time.strftime("%Y-%m-%d")+ " 00:02"
yesterday = time.strftime("%Y-%m-%d",time.localtime(time.time() - 24*60*60)) + " 00:02"
get_soapInfo("118114",yesterday,today)
print "finished"
【python】soap获取wsdl的一个例子
最新推荐文章于 2024-07-26 17:15:21 发布