Unverified Commit 8e42a657 authored by 老广's avatar 老广 Committed by GitHub

Merge pull request #1560 from wojiushixiaobai/dev

[Update]替换淘宝IP查询接口
parents c94d018d e1fff18c
...@@ -212,10 +212,10 @@ def write_login_log(*args, **kwargs): ...@@ -212,10 +212,10 @@ def write_login_log(*args, **kwargs):
def get_ip_city(ip, timeout=10): def get_ip_city(ip, timeout=10):
# Taobao ip api: http://ip.taobao.com//service/getIpInfo.php?ip=8.8.8.8 # Taobao ip api: http://ip.taobao.com/service/getIpInfo.php?ip=8.8.8.8
# Sina ip api: http://int.dpool.sina.com.cn/iplookup/iplookup.php?ip=8.8.8.8&format=json # Sina ip api: http://int.dpool.sina.com.cn/iplookup/iplookup.php?ip=8.8.8.8&format=json
url = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?ip=%s&format=json' % ip url = 'http://ip.taobao.com/service/getIpInfo.php?ip=%s' % ip
try: try:
r = requests.get(url, timeout=timeout) r = requests.get(url, timeout=timeout)
except: except:
...@@ -224,8 +224,8 @@ def get_ip_city(ip, timeout=10): ...@@ -224,8 +224,8 @@ def get_ip_city(ip, timeout=10):
if r and r.status_code == 200: if r and r.status_code == 200:
try: try:
data = r.json() data = r.json()
if not isinstance(data, int) and data['ret'] == 1: if not isinstance(data, int) and data['code'] == 0:
city = data['country'] + ' ' + data['city'] city = data['data']['country'] + ' ' + data['data']['city']
except ValueError: except ValueError:
pass pass
return city return city
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment