Raise an exception on empty packets (geoip Python class)

This commit is contained in:
Grégory Soutadé 2016-02-04 20:39:50 +01:00
parent 148a2a81c8
commit bc9c8c3dcc

View File

@ -75,11 +75,12 @@ class IPToGeo(object):
try:
self._socket.send(packet)
except IOError, e:
# Give another chance (we may have been disconnected due to timeout
# Give another chance (we may have been disconnected due to timeout)
self._create_socket()
self._socket.send(packet)
packet = self._socket.recv(IPToGeo.PACKET_SIZE)
if not packet:
raise IPToGeoException('Error, empty packet')
(ip, country_code) = self._check_request(packet)
if country_code:
# convert to string