un33k / django-ipware

A Django application to retrieve client's IP address

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Potential bug in version 1.0.0?

holyoaks opened this issue · comments

I'm not sure if this is a bug or not, especially since I've not run into this but the one time, but I figured I'd submit and see if it's something you all want to look at. I received a 500 error from my server when trying to get_real_ip. The call stack is copied below.

File ".\sdcgis\context_processors.py", line 15, in login_context_processor
address = get_real_ip(request)
File "C:\Virtual\Django17\lib\site-packages\ipware\ip.py", line 36, in get_real_ip
return get_ip(request, real_ip_only=True, right_most_proxy=right_most_proxy)
File "C:\Virtual\Django17\lib\site-packages\ipware\ip.py", line 20, in get_ip
if ip_str and is_valid_ip(ip_str):
File "C:\Virtual\Django17\lib\site-packages\ipware\utils.py", line 37, in is_valid_ip
return is_valid_ipv4(ip_str) or is_valid_ipv6(ip_str)
File "C:\Virtual\Django17\lib\site-packages\ipware\utils.py", line 27, in is_valid_ipv6
socket.inet_pton(socket.AF_INET6, ip_str)
AttributeError: 'module' object has no attribute 'inet_pton'

Please include your exact Python version.

2.7.8

Please make sure you don't have a socket.py file in the directory where get_real_ip() is being invoked. Other than that, here are some tests you can run on your system:

$ python
Python 2.7.8 (default, Nov 19 2014, 22:13:14)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.54)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from socket import inet_pton
>>>

$ python
Python 2.7.3 (default, Feb 27 2014, 19:58:35)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from socket import inet_pton
>>>

This has continued to crop up, and I found a potential solution at kinverarity1/webpy@3706180. I tried to create a pull request but received a 403.

I see that the same code is at line 28 of ipware utils.py;

except socket.error:

I expect making the same change will resolve this issue, as shown below.
except (socket.error, AttributeError):