Код: Выделить всё
#Import Libraries
import requests
import folium
from googlemaps import *
#Function to get location
def get_geolocation(ip_address):
response = requests.get(f'http://ipinfo.io/{ip_address}/json')
data = response.json()
return data
#Function to create the map using location data
def create_map(latitude, longitude):
map_ = folium.Map(location=[latitude, longitude], zoom_start=12)
folium.Marker([latitude, longitude], popup='Location').add_to(map_)
return map_
#Read the Ip from the user
ip_address = input("Enter the IP address you want to locate: ")
#Run the function to get location
location_data = get_geolocation(ip_address)
latitude, longitude = map(float, location_data['loc'].split(','))
map_ = create_map(latitude, longitude)
map_.save('map.html')
Код: Выделить всё
latitude, longitude = map(float, location_data['loc'].split(','))
~~~~~~~~~~~~~^^^^^^^
KeyError: 'loc'
Подробнее здесь: https://stackoverflow.com/questions/793 ... e-mapfloat
Мобильная версия