Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the simply-static domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/html/wp-includes/functions.php on line 6121
通过ip获取归属地

通过ip获取归属地

import requests
def get_ip():
   response = requests.get('https://api64.ipify.org?format=json').json()
   return response["ip"]
def get_location():
   ip_address = get_ip()
   response = requests.get(f'https://ipapi.co/{ip_address}/json/').json()
   location_data = {
   "ip": ip_address,
   "city": response.get("city"),
   "region": response.get("region"),
   "country": response.get("country_name")
   }
   return location_data
print(get_location())