cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How can I resolve this SSL error which occurrs when calling databricks-sql-connector/databricks.sql.connect() from my python app?

mattmunz
New Contributor III

Error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:997)

>  python --version

Python 3.10.4

This error seems to be coming from the thrift backend. I suspect but have not confirmed that the python version is involved. This app was previously able to connect under a configuration that used python 3.8.

I'd prefer not to use self-signed certificates. Any help would be appreciated!

5 REPLIES 5

Kaniz
Community Manager
Community Manager

Hi @Matt Munzโ€‹ ,

Insert this code at the beginning of your source file and check.

It was found over here:-

import ssl
 
try:
    _create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
    # Legacy Python that doesn't verify HTTPS certificates by default
    pass
else:
    # Handle target environment that doesn't support HTTPS verification
    ssl._create_default_https_context = _create_unverified_https_context

mattmunz
New Contributor III

@Kaniz Fatmaโ€‹ Thanks for this workaround. Ultimately I do want to verify the certificates so I'd be interested in hearing about any solutions that would allow that as well.

@Matt Munzโ€‹ Were you ever able to find a solution to this issue?

Kaniz
Community Manager
Community Manager

Hi @Matt Munzโ€‹ , We havenโ€™t heard from you on the last response from me, and I was checking back to see if you have a resolution yet. If you have any solution, please share it with the community as it can be helpful to others. Otherwise, we will respond with more details and try to help.

ziggy
New Contributor II

I have the same issue and tried the solution mentioned above. It still did not work. I am getting below error

Error: ('HY000', '[HY000] [Simba][ThriftExtension] (14) Unexpected response from server during a HTTP connection: SSL_connect: certificate verify failed. (14) (SQLDriverConnect)')

I am on Jupyterhub running on Linux

import pyodbc

import ssl

try:

  _create_unverified_https_context = ssl._create_unverified_context

except AttributeError:

  # Legacy Python that doesn't verify HTTPS certificates by default

  pass

else:

  # Handle target environment that doesn't support HTTPS verification

  ssl._create_default_https_context = _create_unverified_https_context

   

   

conn = pyodbc.connect("Driver=/opt/simba/spark/lib/64/libsparkodbc_sb64.so;" +

           "HOST=;" +

           "PORT=443;" +

           "Schema=default;" +

           "SparkServerType=3;" +

           "AuthMech=3;" +

           "UID=token;" +

           "PWD=;" +

           "ThriftTransport=2;" +

           "SSL=1;" +

           "HTTPPath=;" +

           "ssl_ca=rootdbcert.cer;" +

           "sslverify=0",

           autocommit=True)

Where should the SSL certificate reside? I uploaded it to the same project folder where the python script is running. I gave the drive path mentioned in

https://docs.databricks.com/dev-tools/pyodbc.html

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.