<form id="pblhr"><nobr id="pblhr"></nobr></form>
              <form id="pblhr"><nobr id="pblhr"><th id="pblhr"></th></nobr></form>

                <address id="pblhr"></address>

                當前位置: 首頁 / 技術分享 / 正文
                好程序員Python培訓Python如何調用服務接口

                2020-11-06

                Python培訓

                  好程序員Python培訓Python如何調用服務接口,關于Python如何調用服務接口這個問題曾經也有不少的小伙伴詢問過,本篇文章小編就給讀者們實例介紹一下Python如何調用服務接口,希望對小伙伴有幫助。

                pic-01

                 

                下面上代碼:

                #! /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[]=%dmeters[]=%dmeters[]=%dmeters[]=%dmeters[]=%s" % (customerId, productCode, ruleTemplateId, ruleId, operator)

                  params_s += "&url=%s&method=%smeterTypes[]=intmeterTypes[]=intmeterTypes[]=intmeterTypes[]=intmeterTypes[]=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培訓官網、微信公眾號等平臺。

                Python培訓:http://www.blouan.com/python_class.shtml

                好程序員公眾號

                • · 剖析行業發展趨勢
                • · 匯聚企業項目源碼

                好程序員開班動態

                More+
                • HTML5大前端 <高端班>

                  開班時間:2021-04-12(深圳)

                  開班盛況

                  開班時間:2021-05-17(北京)

                  開班盛況
                • 大數據+人工智能 <高端班>

                  開班時間:2021-03-22(杭州)

                  開班盛況

                  開班時間:2021-04-26(北京)

                  開班盛況
                • JavaEE分布式開發 <高端班>

                  開班時間:2021-05-10(北京)

                  開班盛況

                  開班時間:2021-02-22(北京)

                  開班盛況
                • Python人工智能+數據分析 <高端班>

                  開班時間:2021-07-12(北京)

                  預約報名

                  開班時間:2020-09-21(上海)

                  開班盛況
                • 云計算開發 <高端班>

                  開班時間:2021-07-12(北京)

                  預約報名

                  開班時間:2019-07-22(北京)

                  開班盛況
                在線咨詢
                試聽
                入學教程
                立即報名

                Copyright 2011-2020 北京千鋒互聯科技有限公司 .All Right 京ICP備12003911號-5 京公網安備 11010802035720號

                骚货在线

                      <form id="pblhr"><nobr id="pblhr"></nobr></form>
                            <form id="pblhr"><nobr id="pblhr"><th id="pblhr"></th></nobr></form>

                              <address id="pblhr"></address>