Skip to content

Commit

Permalink
Merge pull request #11 from ipinfo/uman/index-error-fix
Browse files Browse the repository at this point in the history
Bug fix to bad coordinate reading on private IPs.
  • Loading branch information
UmanShahzad authored Mar 17, 2019
2 parents 44747a5 + e9303d8 commit 62fef91
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ipinfo/details.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __getattr__(self, attr):
if attr in self.details:
return self.details[attr]
else:
raise AttributeError('{attr} is not a valid attribute of Details'.format(attr))
raise AttributeError('{} is not a valid attribute of Details'.format(attr))

@property
def all(self):
Expand Down
17 changes: 9 additions & 8 deletions ipinfo/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,7 @@ def getDetails(self, ip_address=None):
raw_details = self._requestDetails(ip_address)
raw_details['country_name'] = self.countries.get(raw_details.get('country'))
raw_details['ip_address'] = ipaddress.ip_address(raw_details.get('ip'))

lat, lon = None, None
coords = tuple(raw_details.get('loc', '').split(','))
if coords:
lat, lon = coords[0], coords[1]
raw_details['latitude'], raw_details['longitude'] = lat, lon

raw_details['latitude'], raw_details['longitude'] = self._read_coords(raw_details.get('loc'))
return Details(raw_details)

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

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

return headers

def _read_coords(self, location):
lat, lon = None, None
coords = tuple(location.split(',')) if location else ''
if len(coords) == 2 and coords[0] and coords[1]:
lat, lon = coords[0], coords[1]
return lat, lon

def _read_country_names(self, countries_file=None):
"""Read list of countries from specified country file or default file."""
if not countries_file:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""

setup(name='ipinfo',
version='1.1.0',
version='1.1.1',
description='Official Python library for IPInfo',
long_description=long_description,
url='https://github.com/ipinfo/python',
Expand Down

0 comments on commit 62fef91

Please sign in to comment.