科技知识动态:基于Python的移动联通基站接口调用代码实例

导读跟大家讲解下有关基于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中文网

免责声明:本文由用户上传,如有侵权请联系删除!