This document describes how to call the interface of a mobile Unicom base station on aggregated data. the document address is www. juhe. cndocsapiid8 #! Usrbinpython #-*-coding: UTF-8-*-importjson, urllibfromurllibimporturlencode #----------------------------------...
#! /Usr/bin/python #-*-coding: UTF-8-*-import json, urllibfrom urllib import urlencode # ---------------------------- # sample code for calling a mobile Unicom base station-aggregate data # Online interface documentation: http://www.juhe.cn/docs/8#---------------------------------- Def main (): # configure the APPKey appkey = "*************************" #1. base station location request1 (appkey, "GET") # base station location def request1 (appkey, m = "GET"): url =" http://v.juhe.cn/cell/get "Params = {" mnc ":" ", # mobile base station: 0 Unicom base station: 1 default: 0" lac ":" ", # cell ":"", # base station number "hex": "", # hexadecimal type, 16 or 10, default: 10 "dtype": "", # returned data format: json/xml/jsonp "callback": "", # "key": appkey, # APPKEY} params = urlencode (params) must be passed when jsonp format is selected) 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: # successful request print res ["result"] else: print "% s: % s "% (res [" error_code "], res [" reason "]) else: print "request api error" if _ name _ = '_ main _': main ()