gridstatus / gridstatusio

Python client for accessing the GridStatus.io Hosted API.
https://www.gridstatus.io
BSD 3-Clause "New" or "Revised" License
26 stars 3 forks source link

SSL Error #29

Closed UtilityScience closed 5 months ago

UtilityScience commented 5 months ago

I've downloaded the package, imported it into my Python session and tried testing one of the first examples provided in the getting started section:

import gridstatusio as gs

API_KEY='####'

client= gs.GridStatusClient(API_KEY)

client.list_datasets(filter_term='ERCOT SPP')

However, when I run this code I get the following error message:

SSLError: HTTPSConnectionPool(host='api.gridstatus.io', port=443): Max retries exceeded with url: /v1/datasets/?return_format=json&json_schema=array-of-arrays (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)')))

Other documentation I found for similar errors supported a verify=False argument, but it doesn't look like I can workaround that with this package. Do you have any suggestions?

Thank you!

kmax12 commented 5 months ago

@UtilityScience i think this is likely due to a missing or outdated certificate authority (CA) bundle on the local machine. what operating system are you using? can you also share the version of python and the version of the other packages installed using pip freeze?

UtilityScience commented 5 months ago

@kmax12 I'm using Windows 10. Python version is 3.11.4, gridstatusio = 0.5.6

UtilityScience commented 5 months ago

I should add that I work at a municipal utility; I'm more of an energy resource planner than a computer scientist so I'm not sure how our firewall rules may affect this process.

kmax12 commented 5 months ago

It's possible the firewall is breaking things. I haven't heard reports of this issue from others, so I am fairly confident this is an issue with how SSL Certificates are working locally.

One thing to try is to install https://pypi.org/project/certifi/ and then set this environment variable pointing to certificate

set REQUESTS_CA_BUNDLE=path\to\cacert.pem

after the enviroment variable is set. restart python / notebook and rerun things

if that doesn't work, it may be worth trying on a different network or computer

UtilityScience commented 5 months ago

I'm still getting the error but I may not have set the variable in the right place. I'll pick it back up tomorrow morning and see about getting the certificate updated somehow. Thank you for your help.

UtilityScience commented 5 months ago

It's working! I retrieved the certificate chain from gridstatus.io, opened it in Notepad ++, then copy and pasted that information into the cacert.pem file.