PyHSPF icon indicating copy to clipboard operation
PyHSPF copied to clipboard

SSL Certificate error while running cdlexample01.py

Open mahdipoor opened this issue 7 years ago • 1 comments

I am trying to test run PyHSPF on my windows machine with Python 3.6. All the simple test examples are working, but some of the more sophisticated ones not. Currently I am getting this error while trying to run cdlexample01.py

`File "C:\Research\PyHSPF-master\examples\gis\cdlexample01.py", line 58, in cdlextractor.download_data(state, years) File "C:\Users\AmIn\AppData\Local\Programs\Python\Python36\Lib\site-packages\pyhspf\preprocessing\cdlextractor.py", line 733, in download_data request.urlretrieve(url, local, self.report) File "C:\Users\AmIn\AppData\Local\Programs\Python\Python36\Lib\urllib\request.py", line 248, in urlretrieve with contextlib.closing(urlopen(url, data)) as fp: File "C:\Users\AmIn\AppData\Local\Programs\Python\Python36\Lib\urllib\request.py", line 223, in urlopen return opener.open(url, data, timeout) File "C:\Users\AmIn\AppData\Local\Programs\Python\Python36\Lib\urllib\request.py", line 526, in open response = self._open(req, data) File "C:\Users\AmIn\AppData\Local\Programs\Python\Python36\Lib\urllib\request.py", line 544, in _open '_open', req) File "C:\Users\AmIn\AppData\Local\Programs\Python\Python36\Lib\urllib\request.py", line 504, in _call_chain result = func(*args) File "C:\Users\AmIn\AppData\Local\Programs\Python\Python36\Lib\urllib\request.py", line 1361, in https_open context=self._context, check_hostname=self._check_hostname) File "C:\Users\AmIn\AppData\Local\Programs\Python\Python36\Lib\urllib\request.py", line 1320, in do_open raise URLError(err)

urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)>`

mahdipoor avatar Aug 08 '18 23:08 mahdipoor

I was able to get rid of this error message temporarily by adding this to the top of cdlextractor.py

import os, ssl if (not os.environ.get('PYTHONHTTPSVERIFY', '') and getattr(ssl, '_create_unverified_context', None)): ssl._create_default_https_context = ssl._create_unverified_context

This is not a permanent solution, and shouldn't be used with any unsecure website, since it's bypassing ssl verification.

mahdipoor avatar Aug 09 '18 19:08 mahdipoor