'GeoPy SSL Certificate Verify Failed: certificate has expired (_ssl.c:1056)
UPDATE:
Okay, so I was finally able to figure it out. Apparently I accidentally installed something through pip before leaving the other day, which had some sort of conflict with GeoPy. The package in question was called device, and uninstalling it fixed everything.
OP:
my first post here. I'm still learning python, so please excuse any newbie mistakes.
My OS is Windows 10, and I am using Python 3.7.3. I am attempting to get an address using the geopy API, using the geolocator.reverse() function, to which I supply a latitude and longitude which I get using os.popen:
lat, lon = os.popen('curl ipinfo.io/loc').read().split(',')
print(lat, lon)
and I am using the following code to get the address:
geoLoc = Nominatim(user_agent="GetLoc", scheme='http')
locname = geoLoc.reverse(str(lat)+","+str(lon))
print(location.address)
This was working fine as of 3:30 PM yesterday afternoon, and I saved it before leaving the office.
However, today when I came back, the same code no longer works (I can only assume there was an update, or someone changed something on my machine while I was gone), and generates a very long error message, which I will post below.
I have looked around for people that have had the same problem, and while I did find some who experienced a similar issue, none of the solutions worked. I tried updating ssl, Geopy, GeoCoders, and certifi, as well as re-installing all of these, but that didn't make any difference.
Here is all the code I am using for this simple script:
import geopy.geocoders
from geopy.geocoders import Nominatim
import os
import certifi
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
# Get ip information
lat, lon = os.popen('curl ipinfo.io/loc').read().split(',')
print(lat, lon)
# calling the Nominatim tool
geoLoc = Nominatim(user_agent="GetLoc", scheme='http') #Program crashes here
# entering the location name
location = geoLoc.reverse(str(lat)+","+str(lon))
# print address
print(location.address)
And below is the full output + error messages it's giving me. Is there something wrong with the GeoPy API? I spent perhaps 4 hours looking for a solution, but never found anything that worked.
C:\Python Scripts>python geo.py
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 17 100 17 0 0 144 0 --:--:-- --:--:-- --:--:-- 145
34.7304 -86.5859
Traceback (most recent call last):
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 541, in urlopen
body=body, headers=headers)
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 366, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1016, in _send_output
self.send(msg)
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 956, in send
self.connect()
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 131, in connect
ssl_version=resolved_ssl_version)
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\packages\urllib3\util.py", line 617, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 412, in wrap_socket
session=session
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 853, in _create
self.do_handshake()
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1117, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1056)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\adapters.py", line 319, in send
timeout=timeout
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 574, in urlopen
raise SSLError(e)
requests.packages.urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1056)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\site-packages\geopy\adapters.py", line 448, in _request
resp = self.session.get(url, timeout=timeout, headers=headers)
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\sessions.py", line 369, in get
return self.request('GET', url, **kwargs)
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\sessions.py", line 357, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\sessions.py", line 480, in send
history = [resp for resp in gen] if allow_redirects else []
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\sessions.py", line 480, in <listcomp>
history = [resp for resp in gen] if allow_redirects else []
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\sessions.py", line 144, in resolve_redirects
allow_redirects=False,
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\sessions.py", line 460, in send
r = adapter.send(request, **kwargs)
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\adapters.py", line 358, in send
raise SSLError(e)
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1056)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "geo.py", line 15, in <module>
location = geoLoc.reverse(str(lat)+","+str(lon))
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\site-packages\geopy\geocoders\nominatim.py", line 362, in reverse
return self._call_geocoder(url, callback, timeout=timeout)
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\site-packages\geopy\geocoders\base.py", line 368, in _call_geocoder
result = self.adapter.get_json(url, timeout=timeout, headers=req_headers)
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\site-packages\geopy\adapters.py", line 438, in get_json
resp = self._request(url, timeout=timeout, headers=headers)
File "C:\Users\CalebC\AppData\Local\Programs\Python\Python37\lib\site-packages\geopy\adapters.py", line 460, in _request
raise GeocoderUnavailable(message)
geopy.exc.GeocoderUnavailable: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1056)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
