connector-x icon indicating copy to clipboard operation
connector-x copied to clipboard

Authentication Error for SQL Server (MSSQL) when Connection URL contains special characters

Open aleewen opened this issue 1 year ago • 3 comments

What language are you using?

Python

What version are you using?

python: 3.11.8 connectorx: 0.3.2

What database are you using?

Microsoft SQL Server (MSSQL)

What dataframe are you using?

Pandas and/or Polars

Can you describe your bug?

Authentication works with the SQL Alchemy engine but not ConnectorX with the same connection url

What are the steps to reproduce the behavior?

I have a username with the following special character: \

I have a password with the following special characters: !`>]

I am URL encoding both of them with quote_plus.

Database setup if the error only happens on specific data or data type

N/A

Example query / code
from sqlalchemy.engine import URL, create_engine

driver_string = 'FreeTDS'
db_username = "my\\username"
db_password = r'my_special_password_`!]>'
db_username_url = quote_plus(db_username)
db_password_url = quote_plus(db_password)
port = 1433
tds_version = 'auto'

connection_url: str = (
    URL
    .create(
        drivername="mssql+pyodbc",
        username=db_username_url,
        password=db_password_url,
        host=server,
        port=port,
        database=database,
        query={"driver": driver_string,
               "TDS_Version": tds_version,
               "UseNTLMv2": "Yes"}
    )
    .render_as_string(hide_password=False)
)

# This works
my_engine = create_engine(connection_url)
my_engine.connect()

# This doesn't work
cx.read_sql(connection_url, "SELECT 1", return_type='polars')

What is the error?

ERROR tiberius::tds::stream::token] Login failed for user my\username'. code=18456

aleewen avatar May 09 '24 17:05 aleewen

I can confirm this bug happens for Trino as well. Do we have this on the roadmap?

Scot-Survivor avatar Jul 17 '24 09:07 Scot-Survivor

Any updates to this issue?

Scot-Survivor avatar Sep 07 '24 10:09 Scot-Survivor