for row in rows: ip=row[1] count=str(row[0]) match = reader.get(ip) if match: try: country=match['country']['names']['en'] except: country="unknown" else: country="unknown"