HTTPSConnectionPool(host='oauth2.googleapis.com', port=443): Max retries exceeded with url: /token (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1000)')))
lpcoutinho opened this issue · comments
Luiz Paulo Coutinho commented
Hi there!
This code of mine worked perfectly on AWS. However, I needed to migrate to the Contabo server and now this error is appearing. I already searched on StackOverflow but it was not answered there and the solution I found here is old and didn't work for me.
I'm using Streamlit and at some point I need to consult a spreadsheet in Googlesheets
To Reproduce
import streamlit as st
import gspread
gc = gspread.service_account(filename="google.json")
planilha = gc.open_by_url(
"my_url"
)
This didn't happen before, now I have this error
TransportError: HTTPSConnectionPool(host='oauth2.googleapis.com', port=443): Max retries exceeded with url: /token (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1000)')))
Traceback:
File "/usr/local/lib/python3.12/dist-packages/streamlit/runtime/scriptrunner/script_runner.py", line 542, in _run_script
exec(code, module.__dict__)
File "/root/mcenter_streamlit/app/1_📤_BUENOSHOPS_-_FULFILLMENT.py", line 2106, in <module>
planilha = gc.open_by_url(
^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/gspread/client.py", line 227, in open_by_url
return self.open_by_key(extract_id_from_url(url))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/gspread/client.py", line 206, in open_by_key
spreadsheet = Spreadsheet(self, {"id": key})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/gspread/spreadsheet.py", line 37, in __init__
metadata = self.fetch_sheet_metadata()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/gspread/spreadsheet.py", line 245, in fetch_sheet_metadata
r = self.client.request("get", url, params=params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/gspread/client.py", line 80, in request
response = getattr(self.session, method)(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/requests/sessions.py", line 602, in get
return self.request("GET", url, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/google/auth/transport/requests.py", line 537, in request
self.credentials.before_request(auth_request, method, url, request_headers)
File "/usr/local/lib/python3.12/dist-packages/google/auth/credentials.py", line 230, in before_request
self._blocking_refresh(request)
File "/usr/local/lib/python3.12/dist-packages/google/auth/credentials.py", line 193, in _blocking_refresh
self.refresh(request)
File "/usr/local/lib/python3.12/dist-packages/google/oauth2/service_account.py", line 445, in refresh
access_token, expiry, _ = _client.jwt_grant(
^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/google/oauth2/_client.py", line 308, in jwt_grant
response_data = _token_endpoint_request(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/google/oauth2/_client.py", line 268, in _token_endpoint_request
response_status_ok, response_data, retryable_error = _token_endpoint_request_no_throw(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/google/oauth2/_client.py", line 215, in _token_endpoint_request_no_throw
request_succeeded, response_data, retryable_error = _perform_request()
^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/google/oauth2/_client.py", line 191, in _perform_request
response = request(
^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/google/auth/transport/requests.py", line 192, in __call__
raise new_exc from caught_exc
Environment info:
- Ubuntu 20.04.6 LTS
- Python 3.12.2
- gspread 5.12.4
Luiz Paulo Coutinho commented
I ended up finding the solution.
I installed CA Certificates:
sudo apt-get update && sudo apt-get install ca-certificatessudo apt-get update && sudo apt-get install ca-certificates
Then I set the Environment Variable for SSL Certificates
export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
Alexandre Lavigne commented
Hi thank you for bringing a solution to your issue.
Not related to gspread, closing this issue