Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch connection issues to minIO server?

I'm trying to catch authentication errors on a Python client for minio (minio package):

from minio import Minio
from minio.error import MinioError, ResponseError

## Data Lake (Minio)
try :
    minioClient = Minio(endpoint= config['databases']['datalake']['hostip']+":"+config['databases']['datalake']['port'],
                access_key= config['databases']['datalake']['accesskey'],
                secret_key= config['databases']['datalake']['secretkey'],
                secure= False)

    app.logger.info("MinIO Server Connected!")

except MinioError as e:
    app.logger.info("Could not connect to MinIO Server")

I can't seem to be able to catch an authentication error when using fake (wrong) creds. It's always a pass... Any ideas on how to catch these sort of issues?

like image 242
Leitouran Avatar asked Aug 31 '25 04:08

Leitouran


1 Answers

The Minio() only creates an object, but does not connect to a server. Therefore, the object creation works with fake credentials or fake urls and param also, as this object is not used to connect somewhere for now. Your exception handling only tries to catch raised errors that occur from simple python object creation.

To check the connectivity, I try to connect to a non existing bucket. If I get an error message, everything is fine, if there is a timeout, you can catch it and log it. (You could also try to connect to a existing bucket, but this increases complexity in checking whether there is an error in creating/reaching this bucket or the storage)

#create object

client = Minio(
    host,
    access_key=user,
    secret_key=pass,
    more_access_data=...
)

# reach storage
try:
    if not client.bucket_exists("nonexistingbucket"):
        logging.debug("Object storage connected")
except:
    # raise error if storage not reachable
    logging.critical("Object storage not reachable")
like image 119
Lithilion Avatar answered Sep 02 '25 17:09

Lithilion