Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aleewen opened this issue May 9, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@aleewen
Copy link

aleewen commented May 9, 2024

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 aleewen added the bug Something isn't working label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant