http協議:
http://api.youripapi.com/ip/
https協議:
https://api.youripapi.com/ip/
* API接口可能會因為各種網絡原因和攻擊都可能産生阻斷,請開發時做好冗餘和異常處理
* 當HTTP請求返回的狀態碼非200時,請做異常處理,比如 202 狀態碼造成的原因可能是無效Token、餘額不足、格式錯誤
Python調用iP查詢接口示例:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import httplib2
from urllib.parse import urlencode #python3
#from urllib import urlencode #python2
params = urlencode({'ip':'9.8.8.8','datatype':'jsonp','callback':'find'})
url = 'https://api.youripapi.com/ip/?'+params
headers = {"token":"8594766483a2d65d76804906dd1a1c6a"}#token為示例
http = httplib2.Http()
response, content = http.request(url,'GET',headers=headers)
print(content.decode("utf-8"))