Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Password with @ can't connect the database [duplicate]

When I tried to connect database from Python, my password contains special character say for example: 123@789. My Connection fails because of this.

I make connection to the database as follows:

engine = sqlalchemy.create_engine('sybase+pyodbc://user:123@789@Database')
like image 844
James Avatar asked Nov 25 '25 02:11

James


1 Answers

URL-encode the @ in the password. Adapted from https://docs.sqlalchemy.org/en/13/core/engines.html,

import urllib.parse
password = urllib.parse.quote_plus("123@789")  # '123%40456'
engine = sqlalchemy.create_engine(f'sybase+pyodbc://user:{password}@Database')

Alternatively, let sqlalchemy generate the URL for you using sqlalchemy.engine.url.URL.

like image 59
chepner Avatar answered Nov 27 '25 17:11

chepner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!