您好,登錄后才能下訂單哦!
怎么在Python中調用服務接口?很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。
如下所示:
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中即為參數,以空格分隔
看完上述內容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注億速云行業資訊頻道,感謝您對億速云的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。