Python調(diào)用服務(wù)接口的實例
更新時間:2019年01月03日 08:55:29 作者:商商-77
今天小編就為大家分享一篇Python調(diào)用服務(wù)接口的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
如下所示:
#! /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腳本,即可調(diào)用相應(yīng)的接口修改數(shù)據(jù)庫數(shù)據(jù)。
python ChangeCustomerRule.py text.txt
text.txt中即為參數(shù),以空格分隔
以上這篇Python調(diào)用服務(wù)接口的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
pytorch:torch.mm()和torch.matmul()的使用
今天小編就為大家分享一篇pytorch:torch.mm()和torch.matmul()的使用,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-12-12
關(guān)于Pycharm配置翻譯插件Translation報錯更新TTK失敗不能使用的問題
這篇文章主要介紹了關(guān)于Pycharm配置翻譯插件Translation報錯更新TTK失敗不能使用的問題,本文通過圖文并茂的形式給大家分享解決方案,需要的朋友可以參考下2022-04-04
Django模板標(biāo)簽中url使用詳解(url跳轉(zhuǎn)到指定頁面)
這篇文章主要介紹了Django模板標(biāo)簽中url使用詳解(url跳轉(zhuǎn)到指定頁面),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03

