Some questions about API (3)

The author introduced some basic knowledge about API in the previous two articles, and then let's take a practical look at the application of API.

First of all: we go to find the API program we need, there are already packaged, we only need to call it.

We can find some APIs in various cloud markets. Here I will do a process of querying the PI of the mobile phone number attribution.

Here are some parameters of the API we bought:

 

 

Let's use Python code to demonstrate how to call this API program

The following is the source code of this program (code for the Python3 version):

import urllib.request
import ssl
from urllib.parse import quote
import string

host = 'http://plocn.market.alicloudapi.com'
path = '/plocn'
method = 'GET'
appcode = '你自己的AppCode'
querys = 'n=175********'              # n值为所要查询的手机号码
bodys = {}
url = host + path + '?' + querys
newurl = quote(url,safe=string.printable)
request = urllib.request.Request(newurl)
request.add_header('Authorization', 'APPCODE ' + appcode)
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
response = urllib.request.urlopen(request, context=ctx)
content = response.read()
if (content):
    print(content.decode('UTF-8'))

After we set everything up, we can call this so-called API. When we call this API successfully, it will return the value we queried.

This is a simple API called by the author. We can embed some of these APIs into our programs and call it when needed.

The following pictures taken by the author from the cloud server, the main ones that can be inquired are some millisecond-level responses, the national mobile phone three networks: China Mobile, China Unicom, telecommunications mobile phone number attribution query, virtual operator, high accuracy, fast response, Hundreds of millions of data, timely update and authoritative data.

Guess you like

Origin blog.csdn.net/qq_39530692/article/details/104128648