-
Notifications
You must be signed in to change notification settings - Fork 28
Description
Describe the bug
I am working behind a corporate security proxy which signs internet traffic using a self-signed certificate. I tried to use msql-python to connect to a SQL Server 2022 instance and use TrustServerCertificate=yes to skip the SSL/TLS validation, but I suspect that it isn't being honored; the module reports a certificate verify error after a successful authentication.
When I use ODBC Driver 18 for SQL Server to build the connection myself, the same parameter TrustServerCertificate=yes works (and using no gives a certificate validation error).
I also tried the options Yes, True, and true, with no success. The documentation examples say however that the syntax is yes.
The full exceptions details below (message and stack trace).
Exception message: RuntimeError: [Microsoft][ODBC Driver 18 for SQL Server]SSL Provider: [error:0A000086:SSL routines::certificate verify failed:self-signed certificate]
Stack trace:
Traceback (most recent call last):
File "<python-input-19>", line 4, in <module>
conn = mssql_python.connect(conn_str)
File "/home/XXX/miniconda3/envs/python3.14/lib/python3.14/site-packages/mssql_python/db_connection.py", line 46, in connect
conn = Connection(
connection_str,
...<3 lines>...
**kwargs
)
File "/home/XXX/miniconda3/envs/python3.14/lib/python3.14/site-packages/mssql_python/connection.py", line 239, in __init__
self._conn = ddbc_bindings.Connection(
~~~~~~~~~~~~~~~~~~~~~~~~^
self.connection_str, self._pooling, self._attrs_before
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
RuntimeError: [Microsoft][ODBC Driver 18 for SQL Server]SSL Provider: [error:0A000086:SSL routines::certificate verify failed:self-signed certificate]
To reproduce
Reproducing requires that you are behind a corporate proxy that uses a self-signed certificate to sign off network traffic. I have appropriately set the HTTPS_PROXY, HTTP_PROXY, CURL_CA_BUNDLE, REQUESTS_CA_BUNDLE environment variables.
import mssql_python
conn_str = "Server=REDACTED;Database=REDACTED;Authentication=ActiveDirectoryInteractive;TrustServerCertificate=yes;"
conn = mssql_python.connect(conn_str) # opens web browser and authenticates successfully, but then prints the error listed above
# -----------------------
import pyodbc
# I have aquired a Kerberos ticket, so that Trusted_Connection works
connection_string = (
'DRIVER={ODBC Driver 18 for SQL Server};'
'SERVER=REDACTED;'
'DATABASE=REDACTED;'
'Trusted_Connection=yes;'
'TrustServerCertificate=yes;'
)
cnxn = pyodbc.connect(connection_string) # succeedsExpected behavior
I expect the parameter TrustServerCertificate=yes; to be honored by the DDBC so that the driver doesn't complain about a self-signed certificate in the chain.
Further technical details
Python version: 3.14.1
SQL Server version: SQL Server 2022
MSSQL-Python: 1.0.0
Operating system: Ubuntu 20.04.6 on Windows Subsystem for Linux
Additional context
Reproducing requires that you are behind a corporate proxy that uses a self-signed certificate to sign off network traffic.