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

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED], but requests works #2

Closed
denis-bz opened this issue Aug 19, 2021 · 3 comments

Comments

@denis-bz
Copy link

Hi Jules,
I'm getting ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED]
in GWAReader, test.py and logfile below. requests works though ?

Actually, instead of a request for lat/lon one at a time, you can download a .tif for a whole country
e.g. https://globalwindatlas.info/api/gis/country/FRA/wind-speed/100
and get data wherever you want with rasterio / rioxarray (I'm no expert, they're way too big.)
Thanks, cheers
-- denis

#!/usr/bin/env python3
# https://github.com/jules-ch/wind-stats
# wind_stats/gwa_reader.py
# 2021-08-19 aug [email protected]

import sys
import requests
from urllib.request import Request, urlopen, __version__

print( "python", sys.version.split()[0] )
print( "requests.__version__", requests.__version__ )
print( "urllib.request.__version__", __version__ )

lat, lon = 48.4569, 5.583  # -> 48.444, 5.583
url = f"https://globalwindatlas.info/api/gwa/custom/Lib/?lat={lat}&long={lon}"
print( "url:", url )

#...............................................................................
req = requests.get( url ).text
lines = req.splitlines()
print( "\nrequests.get( url ): %s lines \n%s \n..." % (
        len(lines), "\n".join( lines[:5] )))

print( "\nurllib.request.Request( url ) --" )
request = Request( url,
    headers={"Referer": "https://globalwindatlas.info"},
    )

print( "\nurllib.request.urlopen(request) --" )
with urlopen(request) as f:
    data = f.read()
    # data = GWAReader.loads( data )
# from: urllib-Request.py
# 19 Aug 2021 13:58z  py/wind/stats  Denis-iMac 10.10.5

python 3.7.9
requests.__version__ 2.26.0
urllib.request.__version__ 3.7
url: https://globalwindatlas.info/api/gwa/custom/Lib/?lat=48.4569&long=5.583

requests.get( url ): 59 lines 
Global Wind Atlas 3.0 (WRF 3-km)<coordinates>5.583,48.444,0.0</coordinates>
5 5 12
    0.000     0.030     0.100     0.400     1.500
     10.0      50.0     100.0     150.0     200.0
     3.72     5.19     9.26    10.05     4.14     4.14     7.34    10.89    16.65    14.81     8.23     5.59 
...

urllib.request.Request( url ) --

urllib.request.urlopen(request) --
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1350, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1277, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1323, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1272, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1032, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 972, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1447, in connect
    server_hostname=server_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 423, in wrap_socket
    session=session
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 870, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1139, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1091)

During handling of the above exception, another exception occurred:
...
@jules-ch
Copy link
Owner

Sorry for the delay,
I've made a fix with requests, you need to have requests installed to use get_gwc_data now.

I've made a release with the fix.

I was using urlib from the stdlib, it's using default CA of your system that are rarely up to date.

@jules-ch
Copy link
Owner

You are right about the raster data that we can download & process. I just found easier to work with GWC file, since I was not going to query a lot of site.

But feel free to open an issue about this.

@denis-bz
Copy link
Author

Hi Jules, a question please (not an issue):
have you spot checked the globalwindatlas maps for France,
do windspeeds and capacity factors look reasonable ?
Any idea which of their data is measured, which extrapolated ?
Thanks, cheers
-- [email protected]

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

2 participants