0

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')
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
James
  • 1
  • 1
  • 1

1 Answers1

6

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.

chepner
  • 497,756
  • 71
  • 530
  • 681