Skip to content

Bug fix to bad coordinate reading on private IPs.#11

Merged
UmanShahzad merged 2 commits intomasterfrom
uman/index-error-fix
Mar 17, 2019
Merged

Bug fix to bad coordinate reading on private IPs.#11
UmanShahzad merged 2 commits intomasterfrom
uman/index-error-fix

Conversation

@UmanShahzad
Copy link
Contributor

@UmanShahzad UmanShahzad commented Mar 15, 2019

Closes #10

Fixes an issue where geolocation data isn't available (e.g. for private IPs) and we try to retrieve it by giving an index, without checking if it's valid for the list.

Was able to reproduce the issue in #10 with:

>>> details = handler.getDetails('10.62.100.139')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mslm/dev/ipinfo/python/ipinfo/handler.py", line 53, in getDetails
    lat, lon = coords[0], coords[1]
IndexError: tuple index out of range

After the fix:

>>> details = handler.getDetails('10.62.100.139')
>>> details.all
{'ip': '10.62.100.139', 'bogon': True, 'country_name': None, 'ip_address': IPv4Address('10.62.100.139'), 'latitude': None, 'longitude': None}
>>> details.latitude
>>> details.longitude
>>> details.bogon
True

and for public IPs:

>>> details = handler.getDetails('9.9.9.9')
>>> details.all
{'ip': '9.9.9.9', 'hostname': 'dns.quad9.net', 'city': '', 'region': '', 'country': 'FR', 'loc': '48.8582,2.3387', 'org': 'AS19281 Quad9', 'country_name': 'France', 'ip_address': IPv4Address('9.9.9.9'), 'latitude': '48.8582', 'longitude': '2.3387'}
>>> details.latitude
'48.8582'
>>> details.longitude
'2.3387'
>>> details.loc
'48.8582,2.3387'
>>> details.country
'FR'

@UmanShahzad
Copy link
Contributor Author

@coderholic and/or @jhtimmins can you review/merge/update pypi?

@UmanShahzad UmanShahzad merged commit 62fef91 into master Mar 17, 2019
@UmanShahzad UmanShahzad deleted the uman/index-error-fix branch March 17, 2019 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ipinfo return an error (IndexError: tuple index out of range) when details of specific IP address is not available.

1 participant