Python調(diào)用服務(wù)接口的實(shí)例
更新時(shí)間:2019年01月03日 08:55:29 作者:商商-77
今天小編就為大家分享一篇Python調(diào)用服務(wù)接口的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
如下所示:
#! /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()
運(yùn)行Python腳本,即可調(diào)用相應(yīng)的接口修改數(shù)據(jù)庫(kù)數(shù)據(jù)。
python ChangeCustomerRule.py text.txt
text.txt中即為參數(shù),以空格分隔
以上這篇Python調(diào)用服務(wù)接口的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關(guān)文章
anaconda jupyter不能導(dǎo)入安裝的lightgbm解決方案
這篇文章主要介紹了anaconda jupyter不能導(dǎo)入安裝的lightgbm解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-03-03
Python自動(dòng)化之?dāng)?shù)據(jù)驅(qū)動(dòng)讓你的腳本簡(jiǎn)潔10倍【推薦】
數(shù)據(jù)驅(qū)動(dòng)是一種思想,讓數(shù)據(jù)和代碼進(jìn)行分離。這篇文章主要介紹了Python自動(dòng)化之?dāng)?shù)據(jù)驅(qū)動(dòng),讓你的腳本簡(jiǎn)潔10倍,需要的朋友可以參考下2019-06-06
Python實(shí)戰(zhàn)之畫(huà)哆啦A夢(mèng)(超詳細(xì)步驟)
這篇文章主要介紹了Python實(shí)戰(zhàn)之畫(huà)哆啦A夢(mèng)(超詳細(xì)步驟),文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)python的小伙伴們有非常好的幫助,需要的朋友可以參考下2021-04-04

