Python-based mobile Unicom base station interface call code instance

Source: Internet
Author: User
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 ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.