Python-based mobile Unicom base station interface Call code instance

Source: Internet
Author: User
Tags urlencode
#!/usr/bin/python#-*-coding:utf-8-*-import json, urllibfrom urllib import UrlEncode #------------------------------- ---# Mobile Unicom base Station invocation sample code-aggregated data # Online interface Documentation: http://www.juhe.cn/docs/8#----------------------------------def main (): #配置您申请的APPK EY appkey = "*********************" #1. Base Station location Request1 (Appkey, "get") #基站定位def Request1 (Appkey, m= "get"): URL = "Http://v.juhe.cn/cell/get" params = {"<font color=red>mnc</font>": "", #<font color=red> move        Base Station: 0 Unicom Base Station: 1 Default:0</font> "Lac": "", #小区号 "cell": ", #基站号" hex ":", #进制类型, 16 or 10, default: 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 ()
  • Related Article

    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.