I have an SSLError in my script that I didn’t have before,
In fact, the same script is running in production without this error, it seems that it only triggers the issue on localhost. This is the error:
google.auth.exceptions.TransportError: HTTPSConnectionPool(host='oauth2.googleapis.com', port=443): Max retries exceeded with url: /token (Caused by SSLError(SSLError(524297, '[X509] PEM lib (_ssl.c:4149)')))
This is very annoying because I can’t make adjustments in the script without being in production, does someone know what could cause this? I’ve read several discussions about this problem but haven’t yet found a solution.
I’m using the google authentication library and the error triggers when I try to access a Google Sheet:
CLIENT = google_authentication('backend/credentials.json')
# GENERAL DATAFRAMES
CLIENTS_DF = read_from_google(
CLIENT.open_by_key(os.getenv("SHEET_CLIENTS_ID")))
This is the google_authentication
function:
import gspread
from google.oauth2.service_account import Credentials
def google_authentication(credentials) -> object:
# Authenticate with Google Sheets using the JSON key file
scope = ['https://www.googleapis.com/auth/spreadsheets',
'https://www.googleapis.com/auth/drive']
creds = Credentials.from_service_account_file(
credentials, scopes=scope)
client = gspread.authorize(creds)
return client
This is the read_from_google
function:
def read_from_google(sheet) -> pd.DataFrame:
""" This function reads the data from the Google Sheet. """
ws = sheet.worksheet('codes')
df_previous = pd.DataFrame(data=ws.get_all_records())
return df_previous
I’ve tried to change the service account but nothing has changed,
Once again the script is working in production, so I wonder if it is something related to my Ubuntu virtual machine,
Thanks in advance
2
Answers
I was able to fix the issue by using a VPS instead of my local machine, which confirms that it's a problem with my Ubuntu. I'm curious if someone has ways of fixing the issue without switching machines. Thanks!
The other way was to make the following:
And add it to
~/.zshrc
and~/.bashrc
.