Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Solved] Import from first hard coded URL fails with "[SSL: CERTIFICATE_VERIFY_FAILED" #54

Open
mborus opened this issue Oct 17, 2021 · 8 comments

Comments

@mborus
Copy link

mborus commented Oct 17, 2021

On windows 10 using Python 3.9.7 the quickstart example crashes at

"nomi = pgeocode.Nominatim('fr')"

with the error

urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed:     certificate has expired (_ssl.c:1129)>

This is probably caused by the Let's Encrypt certificate.

You can do a quick fix by either removing the first URL in line 25 in pgeocode.py or by turning off ssl verification in line 141

import ssl
with urllib.request.urlopen(url, context=ssl._create_unverified_context()) as 
@mborus
Copy link
Author

mborus commented Oct 17, 2021

Update: This seems to be a general Windows Python problem and it's fixable by manually installing the "ISRG Root X1" (https://letsencrypt.org/docs/certificate-compatibility/) - http://woshub.com/updating-trusted-root-certificates-in-windows-10/

Still it would be nice if an SSL error with the first URL would not stop the second one from working.

@mborus mborus changed the title Import from first hard coded URL fails with "[SSL: CERTIFICATE_VERIFY_FAILED" [Solved] Import from first hard coded URL fails with "[SSL: CERTIFICATE_VERIFY_FAILED" Oct 17, 2021
@paul-rupf
Copy link

Hi,
I still have the same error when initiating pgeocode.Nominatim.
I tried to fix the code of pgeocode as suggusted and checked, if ISRG ROOT X1 is installed on my system (Win11). Still, I get the URLError mentioned before.

Do you have any ideas how to fix this issue?

Thanks, Paul

@airqualityanthony
Copy link

You can add ssl._create_default_https_context = ssl._create_unverified_context in line 140 and 158 in pgeocode.py as a temp.

@soysushi
Copy link

Is there another way to solve this issue? adding ssl._create_default is apparently called monkey-patching which is generally not a good practice.

having this same issue here.

@gbilleyPeco
Copy link

Has there been any fix for this issue? I'm running into the same problem. The monkey-patching suggested by @mborus did not work.

Thanks!

@AntmanLFEz
Copy link

Has there been any fix for this issue? I'm running into the same problem. The monkey-patching suggested by @mborus did not work.

Thanks!

I was still unable to get letsencrypt certificates validated even when ensuring "ISRG Root X1" and "ISRG Root X2" were installed.

The simplest solution was to go into pgeocode.py and remove the url starting with https://download.geonames.org from the DOWNLOAD_URL array. The remaining url uses a digicert which has not issues with urllib.

@gbilleyPeco
Copy link

Has there been any fix for this issue? I'm running into the same problem. The monkey-patching suggested by @mborus did not work.
Thanks!

I was still unable to get letsencrypt certificates validated even when ensuring "ISRG Root X1" and "ISRG Root X2" were installed.

The simplest solution was to go into pgeocode.py and remove the url starting with https://download.geonames.org from the DOWNLOAD_URL array. The remaining url uses a digicert which has not issues with urllib.

Wow, that worked! I can't believe it. Thank you!

@nagoli
Copy link

nagoli commented Aug 19, 2024

you can also define the DOWNLOAD_URL var while running pgeocode and remove the s of https url :
pgeocode.DOWNLOAD_URL = [
"http://download.geonames.org/export/zip/{country}.zip",
"http://symerio.github.io/postal-codes-data/data/geonames/{country}.txt",
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants