阿里雲市場IP地址查詢python調用方法

 

阿里雲的IP地址查詢py2示例代碼

import urllib, urllib2, sys


host = 'http://ipquery.market.alicloudapi.com'
path = '/query'
method = 'GET'
appcode = 'xx你的code'
querys = 'ip=58.30.0.0'
bodys = {}
url = host + path + '?' + querys

request = urllib2.Request(url)
request.add_header('Authorization', 'APPCODE ' + appcode)
response = urllib2.urlopen(request)
content = response.read()
if (content):
    print(content)

py3的內容測試

對於python3來說只用urllib即可

import urllib, sys
import urllib.request

host = 'http://ipquery.market.alicloudapi.com'
path = '/query'
method = 'GET'
appcode = '您的appcode'
querys = 'ip=58.30.0.0'
bodys = {}
url = host + path + '?' + querys

request = urllib.request.Request(url)
request.add_header('Authorization', 'APPCODE ' + appcode)
response = urllib.request.urlopen(request)
content = response.read()
if (content):
    print(content)

 

 

#urllib.parse.urlencode(values)

#urllib.urlencode(values)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章