導讀跟大家講解下有關基于Python的移動聯通基站接口調用代碼實例,相信小伙伴們對這個話題應該也很關注吧,現在就為小伙伴們說說基于Python的移
跟大家講解下有關基于Python的移動聯通基站接口調用代碼實例,相信小伙伴們對這個話題應該也很關注吧,現在就為小伙伴們說說基于Python的移動聯通基站接口調用代碼實例,小編也收集到了有關基于Python的移動聯通基站接口調用代碼實例的相關資料,希望大家看到了會喜歡。
#!/usr/bin/python# -*- coding: utf-8 -*-import json, urllibfrom urllib import urlencode #----------------------------------# 移動聯通基站調用示例代碼 - 聚合數據# 在線接口文檔:http://www.juhe.cn/docs/8#---------------------------------- def main(): #配置您申請的APPKey appkey = "*********************" #1.基站定位 request1(appkey,"GET") #基站定位def request1(appkey, m="GET"): url = "http://v.juhe.cn/cell/get" params = { "<font color=red>mnc</font>" : "", #<font color=red>移動基站:0 聯通基站:1 默認:0</font> "lac" : "", #小區號 "cell" : "", #基站號 "hex" : "", #進制類型,16或10,默認:10 "dtype" : "", #返回的數據格式:json/xml/jsonp "callback" : "", #當選擇jsonp格式時必須傳遞 "key" : appkey, #APPKEY } params = urlencode(params) if m =="GET": f = urllib.urlopen("%s?%s" % (url, params)) else: f = urllib.urlopen(url, params) content = f.read() res = json.loads(content) if res: error_code = res["error_code"] if error_code == 0: #成功請求 print res["result"] else: print "%s:%s" % (res["error_code"],res["reason"]) else: print "request api error" if __name__ == '__main__': main()來源:php中文網