Skip to content

Commit 62fef91

Browse files
authored
Merge pull request #11 from ipinfo/uman/index-error-fix
Bug fix to bad coordinate reading on private IPs.
2 parents 44747a5 + e9303d8 commit 62fef91

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

ipinfo/details.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __getattr__(self, attr):
1414
if attr in self.details:
1515
return self.details[attr]
1616
else:
17-
raise AttributeError('{attr} is not a valid attribute of Details'.format(attr))
17+
raise AttributeError('{} is not a valid attribute of Details'.format(attr))
1818

1919
@property
2020
def all(self):

ipinfo/handler.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,7 @@ def getDetails(self, ip_address=None):
4646
raw_details = self._requestDetails(ip_address)
4747
raw_details['country_name'] = self.countries.get(raw_details.get('country'))
4848
raw_details['ip_address'] = ipaddress.ip_address(raw_details.get('ip'))
49-
50-
lat, lon = None, None
51-
coords = tuple(raw_details.get('loc', '').split(','))
52-
if coords:
53-
lat, lon = coords[0], coords[1]
54-
raw_details['latitude'], raw_details['longitude'] = lat, lon
55-
49+
raw_details['latitude'], raw_details['longitude'] = self._read_coords(raw_details.get('loc'))
5650
return Details(raw_details)
5751

5852
def _requestDetails(self, ip_address=None):
@@ -75,13 +69,20 @@ def _get_headers(self):
7569
headers = {
7670
'user-agent': 'IPinfoClient/Python{version}/1.0'.format(version=sys.version_info[0]),
7771
'accept': 'application/json'
78-
}
72+
}
7973

8074
if self.access_token:
8175
headers['authorization'] = 'Bearer {}'.format(self.access_token)
8276

8377
return headers
8478

79+
def _read_coords(self, location):
80+
lat, lon = None, None
81+
coords = tuple(location.split(',')) if location else ''
82+
if len(coords) == 2 and coords[0] and coords[1]:
83+
lat, lon = coords[0], coords[1]
84+
return lat, lon
85+
8586
def _read_country_names(self, countries_file=None):
8687
"""Read list of countries from specified country file or default file."""
8788
if not countries_file:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"""
1010

1111
setup(name='ipinfo',
12-
version='1.1.0',
12+
version='1.1.1',
1313
description='Official Python library for IPInfo',
1414
long_description=long_description,
1515
url='https://github.com/ipinfo/python',

0 commit comments

Comments
 (0)