0

I have use sqlalchemy to run queries to Mysql from python

So far I have used something like this to do so and It has worked perfectly:

from sqlalchemy import create_engine

def start_engine(db_params):
    """Start a connection with the DB used for the session"""
    user = db_params['db_user']
    password = db_params['db_pass']
    host = db_params['db_host']
    port = db_params['db_port']
    schema = db_params['db_schema']

    parms = f'mysql+mysqlconnector://{user}:{password}@{host}:{port}/{schema}'
    print(parms)
            
    engine = create_engine(parms, echo=False, connect_args=connect_args)
    return engine

engine_aurora = start_engine(db_params_aurora)
connection_aurora = engine_aurora.connect()

Nonetheless I'm receiving the error:

InterfaceError: (mysql.connector.errors.InterfaceError) 2003: Can't connect to MySQL server on ''Z1CqsAvFq@main.db.private.aliexp.mx:3306' (8 nodename nor servname provided, or not known)

And I realized this error raises because my password has an @ character like x9+Yeq@Z1CqsAvFq so when creating the string that will be passed to the engine it misunderstands the position of all the parameters

parms = f'mysql+mysqlconnector://{user}:{password}@{host}:{port}/{schema}'

Could you please help me with a way I can overcome this problem?

Thanks in advance!

Moreno
  • 578
  • 1
  • 6
  • 19

0 Answers0