djlampert / PyHSPF

Python extensions to the Hydrological Simulation Program in Fortran (HSPF), including classes for gathering input data, building input files, performing simulations, postprocessing results, calibrating hydrology process parameters, and forecasting climate and land use change effects on water resources
Other
83 stars 51 forks source link

SSL Certificate error while running cdlexample01.py #7

Open mahdipoor opened 6 years ago

mahdipoor commented 6 years ago

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 commented 6 years ago

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.