基于Python的身份证号码归属地数据库调用代码实例 代码描述:基于Python的身份证号码归属地数据库调用代码实例 关联数据:身份证查询 接口平台:聚合数据 #!/usr/bin/python # -*- coding: utf-8 -*- import json, urllib from urllib import urlencode #---------------------------------- # 身份证查询调用示例代码 - 聚合数据 # 在线接口文档:http://www.juhe.cn/docs/38 #---------------------------------- def main(): #配置您申请的APPKey appkey = "*********************" #1.身份证信息查询 request1(appkey,"GET") #2.身份证泄漏查询 request2(appkey,"GET") #3.身份证挂失查询 request3(appkey,"GET") #身份证信息查询 def request1(appkey, m="GET"): url = "http://apis.juhe.cn/idcard/index" params = { "cardno" : "", #身份证号码 "dtype" : "", #返回数据格式:json或xml,默认json "key" : appkey, #你申请的key } 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" #身份证泄漏查询 def request2(appkey, m="GET"): url = "http://apis.juhe.cn/idcard/leak" params = { "cardno" : "", #身份证号码 "dtype" : "", #返回数据格式:json或xml,默认json "key" : appkey, #你申请的key } 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" #身份证挂失查询 def request3(appkey, m="GET"): url = "http://apis.juhe.cn/idcard/loss" params = { "cardno" : "", #身份证号码 "dtype" : "", #返回数据格式:json或xml,默认json "key" : appkey, #你申请的key } 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() 本文来源:https://www.wddqw.com/doc/c1cb82a5a8114431b80dd882.html