Check for presence of country_code field to avoid key error exception
This commit is contained in:
parent
19e9b9d4fb
commit
9bb188b6fc
|
@ -70,11 +70,11 @@ class IWLADisplayTopGeo(IPlugin):
|
|||
cc = None
|
||||
host_name = host.split(' ')[0] # hostname or ip
|
||||
if host_name in self.valid_visitors.keys():
|
||||
cc = self.valid_visitors[host_name]['country_code']
|
||||
cc = self.valid_visitors[host_name].get('country_code', None)
|
||||
else:
|
||||
for visitor in self.valid_visitors.values():
|
||||
if visitor['remote_addr'] == host_name:
|
||||
cc = visitor['country_code']
|
||||
cc = visitor.get('country_code', None)
|
||||
break
|
||||
if not cc or cc == 'ip': return None
|
||||
icon = '<img src="/%s/flags/%s.png"/>' % (self.icon_path, cc)
|
||||
|
|
Loading…
Reference in New Issue
Block a user