Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Exception on IPv6 #20

Closed
KirylKovaliov opened this issue May 11, 2022 · 2 comments
Closed

Getting Exception on IPv6 #20

KirylKovaliov opened this issue May 11, 2022 · 2 comments

Comments

@KirylKovaliov
Copy link

Getting same error on 8.7.3 which seems to be the latest. 8.7.2 works fine for me

from IP2Location import IP2Location
IP2Location(filename="db11.bin").get_all('2806:2f0:9180:8eec:f026:f24c:8a97:e6a2')
Traceback (most recent call last):
  File "/home/disposer/work/regula/v2-licensing-portal/src/tests/local/ip2location_test.py", line 3, in <module>
    IP2Location(filename="db11.bin").get_all('2806:2f0:9180:8eec:f026:f24c:8a97:e6a2')
  File "/home/disposer/.cache/pypoetry/virtualenvs/app-dJLMS_bJ-py3.8/lib/python3.8/site-packages/IP2Location.py", line 315, in get_all
    return self._get_record(addr)
  File "/home/disposer/.cache/pypoetry/virtualenvs/app-dJLMS_bJ-py3.8/lib/python3.8/site-packages/IP2Location.py", line 546, in _get_record
    ipv, ipnum = self._parse_addr(ip)
  File "/home/disposer/.cache/pypoetry/virtualenvs/app-dJLMS_bJ-py3.8/lib/python3.8/site-packages/IP2Location.py", line 477, in _parse_addr
    if is_ipv4(addr) == 4 and '256' not in addr:
  File "/home/disposer/.cache/pypoetry/virtualenvs/app-dJLMS_bJ-py3.8/lib/python3.8/site-packages/IP2Location.py", line 101, in is_ipv4
    if int(ip_parts[i]) > 255:
ValueError: invalid literal for int() with base 10: '2806:2f0:9180:8eec:f026:f24c:8a97:e6a2'

Originally posted by @KirylKovaliov in #19 (comment)

@surajsahoo
Copy link

def is_ipv4(hostname):
ip_parts = hostname.split('.')
for i in range(0,len(ip_parts)):
if int(ip_parts[i]) > 255:
return False
pattern = r'^([0-9]{1,3}[.]){3}[0-9]{1,3}$'
if match(pattern, hostname) is not None:
return 4
return False

Getting Same error due to bug in is_ipv4 function,

In previous version
def is_ipv4(hostname):
pattern = r'^([0-9]{1,3}[.]){3}[0-9]{1,3}$'
ip_parts = hostname.split('.')
if match(pattern, hostname) is not None:
ip_parts = hostname.split('.')
for i in range(0,len(ip_parts)):
if int(ip_parts[i]) > 255:
return False
return 4
return False

ip2location added a commit that referenced this issue May 12, 2022
@ip2location
Copy link
Collaborator

Hi @KirylKovaliov and @surajsahoo,

We have pushed a fix for this issue, please update to 8.7.4 and try again. Thanks for the report!

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

No branches or pull requests

3 participants