Python
sqlalchemy
cx_Oracle

How to escape connection string in cx_Oracle SQLAlchemy

How to escape connection string

If database password contains special characters, connection string should be escaped as URLencode:

  • NG
create_engine('oracle+cx_oracle://user:$$$$@host/database'))
  • OK
create_engine('oracle+cx_oracle://user:%24%24%24%24@host/database')

or

create_engine('oracle+cx_oracle://user:%s@host/database' % urlquote('$$$$'))

References

https://stackoverflow.com/questions/1423804/writing-a-connection-string-when-password-contains-special-characters

http://docs.sqlalchemy.org/en/latest/core/engines.html