Python调用服务接口的实例
2019/7/14 23:46:44
本文主要是介绍Python调用服务接口的实例,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
如下所示:
#! /usr/bin/env python # coding=utf-8 ###################################################################### # Author: yini.xie # Create Time: 2016-07-05 16:28:42 # Descriptioin: ###################################################################### import os import sys import time import json import urllib import urllib2 from urllib import quote from datetime import datetime pathATM = "http://192.168.217.217:4080/invoke.json" def fmtLen(value, length=7): fmt = '{0:>%d}' % (length) return fmt.format(value) def changeWithdrawRule(customerId, productCode, ruleTemplateId, ruleId, operator): service_url_s = "http://service.xxx.com/tsService/TSRuleService_1.0.0" method_s = "bindCustomerWithdrawRuleTemplate" params_s = "parameters[]=%d¶meters[]=%d¶meters[]=%d¶meters[]=%d¶meters[]=%s" % (customerId, productCode, ruleTemplateId, ruleId, operator) params_s += "&url=%s&method=%s¶meterTypes[]=int¶meterTypes[]=int¶meterTypes[]=int¶meterTypes[]=int¶meterTypes[]=java.lang.String" % (service_url_s, method_s) url_s = pathATM + "?" + quote(params_s, safe='&=') data_s = urllib2.urlopen(url_s).read() print url_s return json.loads(data_s) if __name__ == '__main__': start = datetime.now() for line in open(sys.argv[1]).xreadlines(): fields = line.strip().split() customerId = int(fields[0]) productCode = int(fields[1]) ruleTemplateId = int(fields[2]) ruleId = int(fields[3]) print "start to deal customerId = " + str(customerId) changeWithdrawRule(customerId, productCode, ruleTemplateId, ruleId, "Case") end = datetime.now()
运行Python脚本,即可调用相应的接口修改数据库数据。
python ChangeCustomerRule.py text.txt
text.txt中即为参数,以空格分隔
以上这篇Python调用服务接口的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持找一找教程网。
这篇关于Python调用服务接口的实例的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-21Python编程基础教程
- 2024-11-20Python编程基础与实践
- 2024-11-20Python编程基础与高级应用
- 2024-11-19Python 基础编程教程
- 2024-11-19Python基础入门教程
- 2024-11-17在FastAPI项目中添加一个生产级别的数据库——本地环境搭建指南
- 2024-11-16`PyMuPDF4LLM`:提取PDF数据的神器
- 2024-11-16四种数据科学Web界面框架快速对比:Rio、Reflex、Streamlit和Plotly Dash
- 2024-11-14获取参数学习:Python编程入门教程
- 2024-11-14Python编程基础入门