def get(self, ip_address): try: country = geo.get_country_by_ip_address(ip_address) if country: country['ip_address'] = ip_address response = dict(status='OK', data=country) except: response = dict(status='ERROR') self.set_header('Content-Type', 'application/json') self.write(json_encode(response))
def get(self): try: ip_address = self.get_remote_addr() logger.info('Remote IP address is: %s' % ip_address) country = geo.get_country_by_ip_address(ip_address) if country: country['ip_address'] = ip_address response = dict(status='OK', data=country) except: response = dict(status='ERROR') self.set_header('Content-Type', 'application/json') self.write(json_encode(response))