Login fails if password has a curly brace
Describe the bug
Login fails when authenticating with username and password when the password contains a curly brace.
Traceback (most recent call last):
File "/tmp/ipykernel_54945/515371336.py", line 4, in <module>
mssql_python.connect(client.connection_string)
File "/home/ec2-user/.pyenv/versions/3.12.8/envs/dev/lib/python3.12/site-packages/mssql_python/db_connection.py", line 46, in connect
conn = Connection(
^^^^^^^^^^^
File "/home/ec2-user/.pyenv/versions/3.12.8/envs/dev/lib/python3.12/site-packages/mssql_python/connection.py", line 243, in __init__
self._conn = ddbc_bindings.Connection(
^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Login failed for user '<username>'.
logs
DEBUG, logging.py:374, Python, sanitize_connection_string: Sanitizing connection string (length=180)
DEBUG, logging.py:374, Python, sanitize_connection_string: Password fields masked
INFO, logging.py:374, Python, Final connection string: Driver={ODBC Driver 18 for SQL Server};APP=MSSQL-Python;Database=<dbname>;PWD=***;Server=<ipaddress>;TrustServerCertificate=yes;UID=<username>
DEBUG, logging.py:374, Python, PoolingManager.enable: Attempting to enable pooling - max_size=100, idle_timeout=600
INFO, logging.py:374, Python, PoolingManager.enable: Enabling connection pooling - max_size=100, idle_timeout=600 seconds
INFO, logging.py:374, Python, PoolingManager.enable: Connection pooling enabled successfully
DEBUG, connection_pool.cpp:122, DDBC, Creating new connection pool
DEBUG, connection.cpp:22, DDBC, Allocating ODBC environment handle
DEBUG, connection.cpp:63, DDBC, Allocating SQL Connection Handle
DEBUG, connection.cpp:72, DDBC, Connecting to database
DEBUG, connection.cpp:83, DDBC, Creating connection string buffer for macOS/Linux
DEBUG, connection.cpp:86, DDBC, Connection string buffer size=181
DEBUG, connection.cpp:88, DDBC, Connection string buffer created
DEBUG, ddbc_bindings.cpp:1312, DDBC, SQLCheckError: Checking ODBC errors - handleType=2, retcode=-1
DEBUG, connection.cpp:102, DDBC, Disconnecting from database
ERROR, logging.py:374, Python, Error closing database connection: 'Connection' object has no attribute '_conn'
WARNING, logging.py:374, Python, Error during connection cleanup: 'Connection' object has no attribute '_conn'
To reproduce
import mssql_python import traceback server = "<ipaddress>" user = "<username>" password = "aaaaaaaa{aaaaaaaa" connection_string = f'SERVER={server};UID={user};PWD={password};TrustServerCertificate=yes' try: mssql_python.connect(connection_string) except Exception: print(traceback.format_exc()) raise
Expected behavior
Login should work with the given password.
Further technical details
Python version: 3.12.8
SQL Server version: Microsoft SQL Server 2019
Operating system: Amazon Linux 2023
Additional context
I tinkered around with the code and managed find out that there is something wrong with processes relating to the escaping/unescaping of the curly brace. The library encodes the password in the connection string:
PWD=aaaaaaaa{aaaaaaaa;
becomes
PWD={aaaaaaaa{{aaaaaaaa};
AFAIK this is correct, but if I update the code to remove the extra curly brace so that authentincation is made with PWD={aaaaaaaa{aaaaaaaa};, the login completes successfully.