Solution
from simple_geoip import GeoIP
geoip = GeoIP("your-api-key");
try:
data = geoip.lookup("8.8.8.8") # Replace this with your public IP
except ConnectionError:
# If you get here, it means you were unable to reach the geoipify
# service, most likely because of a network error on your end.
except ServiceError:
# If you get here, it means geoipify is having issues, so the request
# couldn't be completed :(
except:
# Something else happened (non-geoipify) related. Maybe you hit CTRL-C
# while the program was running, the kernel is killing your process, or
# something else all together.
print(data)