I'm creating a Flask app, in this part in my routes.py I want to get visitors' country and city from their IP with api.ipgeolocation.io, but get error urllib.error.HTTPError: HTTP Error 423: Locked
import json
from urllib.request import urlopen
from flask import request
...
public_ip = request.remote_addr
url = 'https://api.ipgeolocation.io/ipgeo?apiKey=API_KEY&ip={}'.format(public_ip)
response = urlopen(url)
data = json.load(response)
country = data['country_name']
city = data['city']
I test with fixed IP, ex. 8.8.8.8 it works.
url = 'https://api.ipgeolocation.io/ipgeo?apiKey=API_KEY&ip={}'.format("8.8.8.8")
>>>OUTPUT: United States, Mountain View
I don't know where am I wrong, any help would be greatly appreciated, thanks.