Skip to content

Commit

Permalink
fix for issue cyberdefenders#27
Browse files Browse the repository at this point in the history
Despite the fact that it is a problem with GeoIP lookup, it should not crash the code.
  • Loading branch information
ebdavison authored Apr 11, 2023
1 parent dc0b3f0 commit 25ae2f0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions mha/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ def getCountryForIP(line):
if ip:
ip = ip[0] # take the 1st ip and ignore the rest
if IP(ip).iptype() == 'PUBLIC':
r = reader.country(ip).country
if r.iso_code and r.name:
return {
'iso_code': r.iso_code.lower(),
'country_name': r.name
}
try:
r = reader.country(ip).country
if r.iso_code and r.name:
return {
'iso_code': r.iso_code.lower(),
'country_name': r.name
}
except:
pass
return dict(country=getCountryForIP)


Expand Down

0 comments on commit 25ae2f0

Please sign in to comment.