catch UnicodeError exceptions caused by ip addr string that can't be decoded by ascii decoder

This commit is contained in:
Thomas Waldmann 2014-08-16 21:58:19 +02:00
parent f926c87528
commit 8dbbd0cad0

View File

@ -319,13 +319,14 @@ def _update(host, hostname, ipaddr, secure=False, logger=None):
if not host.available: if not host.available:
# not available is like it doesn't exist # not available is like it doesn't exist
return Response('nohost') return Response('nohost')
try:
ipaddr = str(ipaddr) # bug in dnspython: crashes if ipaddr is unicode, wants a str! ipaddr = str(ipaddr) # bug in dnspython: crashes if ipaddr is unicode, wants a str!
# https://github.com/rthalley/dnspython/issues/41 # https://github.com/rthalley/dnspython/issues/41
# TODO: reproduce and submit traceback to issue 41 # TODO: reproduce and submit traceback to issue 41
try:
kind = check_ip(ipaddr, ('ipv4', 'ipv6')) kind = check_ip(ipaddr, ('ipv4', 'ipv6'))
except ValueError: except (ValueError, UnicodeError):
# invalid ip address string # invalid ip address string
# some people manage to even give a non-ascii string instead of an ip addr
return Response('dnserr') # there should be a better response code for this return Response('dnserr') # there should be a better response code for this
host.poke(kind, secure) host.poke(kind, secure)