skip to Main Content

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


  1. Chosen as BEST ANSWER

    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!


  2. The other way was to make the following:

    export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
    

    And add it to ~/.zshrc and ~/.bashrc.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search