本文主要是介绍【python 调用webserver】python请求调用webservices接口方法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
python webservice接口调用,可以用requests包发起post请求方式,此方法稍微区别是data是XML格式数据。
config.py
from hashlib import md5
import datetime# 请求地址
url="http://10.66.3.19:6039/BaseDataService.asmx"# XML请求参数
#时间戳
# timeStamp=datetime.datetime.now().strftime('%Y%m%d%H%M%S')
timeStamp='20181023131042'
# 签名
timstamp_apitest=timeStamp+"APITEST"
md5_timstamp = md5(timstamp_apitest.encode('utf8')).hexdigest()
sign=md5_timstamp.upper()
print(sign)# 开始日期
START_TIME='2020-10-14'
# 结束日期
END_TIME='2020-10-16'# START_TIME=datetime.datetime.now().strftime('%Y-%m-%d')
# END_TIME=datetime.datetime.now().strftime('%Y-%m-%d')
webServerGetData.py
# -*- coding: utf-8 -*-
# author:laidefa
import requests
from config import *# 设置headers
headers = {'Content-Type': 'text/xml;charset=UTF-8'}# post XML请求参数
body="""
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"><soapenv:Header/><soapenv:Body><tem:TQMSExpertInterface><!--Optional:--><tem:sign>%s</tem:sign><!--Optional:--><tem:timeStamp>%s</tem:timeStamp><!--Optional:--><tem:method>TQMSAssayCheckInfo</tem:method><!--Optional:--><tem:data><![CDATA[<ROOT><START_TIME>%s</START_TIME><END_TIME>%s</END_TIME><TYPE>TQMS</TYPE></ROOT>]]></tem:data></tem:TQMSExpertInterface></soapenv:Body>
</soapenv:Envelope>
"""%(sign,timeStamp,START_TIME,END_TIME)print(body)
r = requests.post(url, data=body.encode("utf-8"), headers=headers)
print(r.status_code)print(r.text)
这篇关于【python 调用webserver】python请求调用webservices接口方法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!