Обязанность моей функции - вычислить расстояние от моего бизнеса до любого адреса (в конце (функция печати) я приведу пример адреса)).Я не знаю, почему он не работает, он что-то говорит об ошибке отслеживания.
Первая часть моей функции конвертирует из адреса в координаты.Вторая часть вычисляет расстояние.
ЭТО КОД
import math
from geopy.geocoders import Nominatim
def Distancia(direccion_domicilio):
geolocator = Nominatim(user_agent="specify_your_app_name_here")
location = geolocator.geocode(direccion_domicilio)
latylon=(location.latitude, location.longitude)
rad=math.pi/180
dif_lat = 20.6072848-(latylon[0])
dif_long = -103.4160099-(latylon[1])
radio=6372.795477598
a=(math.sin(rad*dif_lat/2))**2 + math.cos(rad*location.latitud)*math.cos(rad*20.6072848)*(math.sin(rad*dif_long/2)**2)
distancia=2*radio*math.asin(math.sqrt(a))
return distancia
print(Distancia("Avenida Guadalupe, Real Guadalupe, Jardines de Chapalita, Zapopan, Jalisco, 45030, México"))
ЭТО СООБЩЕНИЕ ОБ ОШИБКЕ
Traceback (most recent call last):
File "C:\Python37\lib\urllib\request.py", line 1317, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "C:\Python37\lib\http\client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Python37\lib\http\client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Python37\lib\http\client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Python37\lib\http\client.py", line 1016, in _send_output
self.send(msg)
File "C:\Python37\lib\http\client.py", line 956, in send
self.connect()
File "C:\Python37\lib\http\client.py", line 1392, in connect
server_hostname=server_hostname)
File "C:\Python37\lib\ssl.py", line 412, in wrap_socket
session=session
File "C:\Python37\lib\ssl.py", line 850, in _create
self.do_handshake()
File "C:\Python37\lib\ssl.py", line 1108, in do_handshake
self._sslobj.do_handshake()
socket.timeout: _ssl.c:1029: The handshake operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python37\lib\site-packages\geopy\geocoders\base.py", line 344, in _call_geocoder
page = requester(req, timeout=timeout, **kwargs)
File "C:\Python37\lib\urllib\request.py", line 525, in open
response = self._open(req, data)
File "C:\Python37\lib\urllib\request.py", line 543, in _open
'_open', req)
File "C:\Python37\lib\urllib\request.py", line 503, in _call_chain
result = func(*args)
File "C:\Python37\lib\urllib\request.py", line 1360, in https_open
context=self._context, check_hostname=self._check_hostname)
File "C:\Python37\lib\urllib\request.py", line 1319, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error _ssl.c:1029: The handshake operation timed out>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Dell\Documents\Python programas\Ejercicios extras\PROYECTOdistancia.py", line 18, in <module>
print(Distancia("Avenida Guadalupe, Real Guadalupe, Jardines de Chapalita, Zapopan, Jalisco, 45030, México"))
File "C:\Users\Dell\Documents\Python programas\Ejercicios extras\PROYECTOdistancia.py", line 6, in Distancia
location = geolocator.geocode(direccion_domicilio)
File "C:\Python37\lib\site-packages\geopy\geocoders\osm.py", line 307, in geocode
self._call_geocoder(url, timeout=timeout), exactly_one
File "C:\Python37\lib\site-packages\geopy\geocoders\base.py", line 367, in _call_geocoder
raise GeocoderTimedOut('Service timed out')
geopy.exc.GeocoderTimedOut: Service timed out