Miserlou / django-easy-timezones

Easy timezones for Django based on GeoIP
http://gun.io/blog/django-easy-timezones/
Apache License 2.0
203 stars 44 forks source link

Add exception handling for invalid IP #9

Closed robbyt closed 9 years ago

robbyt commented 9 years ago

We receive periodic middleware errors from by users with unresolvable IPs (mini-stacktrace attached)

This fix will handle those unresolvable IPs.

...
 File "/srv/virtualenv/current/local/lib/python2.7/site-packages/easy_timezones/middleware.py", line 42, in process_request
   tz = db.time_zone_by_addr(ip)

 File "/srv/virtualenv/current/local/lib/python2.7/site-packages/pygeoip/__init__.py", line 596, in time_zone_by_addr
   ipnum = util.ip2long(addr)

 File "/srv/virtualenv/current/local/lib/python2.7/site-packages/pygeoip/util.py", line 39, in ip2long
   return int(binascii.hexlify(socket.inet_pton(socket.AF_INET6, ip)), 16)

error: illegal IP address string passed to inet_pton
lucas03 commented 9 years ago

Problem is this library does not support IPv6 addresses. There is same geoip file for IPv6 as for IPv4. I have made pull request with IPv6 support, but it was not merged. I admit I did not update docs and did not test it. That might be problem. I thought I would get some comments anyway. https://github.com/Miserlou/django-easy-timezones/pull/7

Miserlou commented 9 years ago

Sorry for not addressing this earlier, I haven't had the time to check on this package and haven't used it in a few years.

IPv6 support is a must, but it needs a proper testing environment. And, more generally, we need a better consensus on what to do in case of failure - ideally something configurable in the settings, with a sane default.

Thanks for bringing this to my attention.