Fix error handling. Well, actually ... implement it :)
This commit is contained in:
parent
5a7dfe7e3c
commit
4147d03607
1 changed files with 8 additions and 3 deletions
|
@ -82,9 +82,6 @@ def get_details(ipaddress, dbfile):
|
||||||
reader = geoip2.database.Reader(dbfile)
|
reader = geoip2.database.Reader(dbfile)
|
||||||
dbtype = reader.metadata().database_type
|
dbtype = reader.metadata().database_type
|
||||||
result = None
|
result = None
|
||||||
country = None
|
|
||||||
continent = None
|
|
||||||
network = None
|
|
||||||
if dbtype == 'GeoLite2-City' or dbtype == 'GeoIP2-City':
|
if dbtype == 'GeoLite2-City' or dbtype == 'GeoIP2-City':
|
||||||
result = reader.city(ipaddress)
|
result = reader.city(ipaddress)
|
||||||
elif dbtype == 'GeoLite2-Country' or dbtype == 'GeoIP2-Country':
|
elif dbtype == 'GeoLite2-Country' or dbtype == 'GeoIP2-Country':
|
||||||
|
@ -98,6 +95,14 @@ def get_details(ipaddress, dbfile):
|
||||||
continent = result.continent.code
|
continent = result.continent.code
|
||||||
network = result.traits.network
|
network = result.traits.network
|
||||||
return "%s,%s,%s" % (country, continent, network)
|
return "%s,%s,%s" % (country, continent, network)
|
||||||
|
except FileNotFoundError as e:
|
||||||
|
raise LookupException(e.args)
|
||||||
|
except maxminddb.errors.InvalidDatabaseError as e:
|
||||||
|
raise LookupException(e.args)
|
||||||
|
except geoip2.errors.AddressNotFoundError as e:
|
||||||
|
raise LookupException(e.args)
|
||||||
|
except ValueError as e:
|
||||||
|
raise LookupException(e.args)
|
||||||
finally:
|
finally:
|
||||||
if reader:
|
if reader:
|
||||||
reader.close()
|
reader.close()
|
||||||
|
|
Loading…
Reference in a new issue