【python】soap获取wsdl的一个例子

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"

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值