Skip to content

Commit 25ae2f0

Browse files
authored
fix for issue cyberdefenders#27
Despite the fact that it is a problem with GeoIP lookup, it should not crash the code.
1 parent dc0b3f0 commit 25ae2f0

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

mha/server.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ def getCountryForIP(line):
3434
if ip:
3535
ip = ip[0] # take the 1st ip and ignore the rest
3636
if IP(ip).iptype() == 'PUBLIC':
37-
r = reader.country(ip).country
38-
if r.iso_code and r.name:
39-
return {
40-
'iso_code': r.iso_code.lower(),
41-
'country_name': r.name
42-
}
37+
try:
38+
r = reader.country(ip).country
39+
if r.iso_code and r.name:
40+
return {
41+
'iso_code': r.iso_code.lower(),
42+
'country_name': r.name
43+
}
44+
except:
45+
pass
4346
return dict(country=getCountryForIP)
4447

4548

0 commit comments

Comments
 (0)