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

Faced error using Databricks SQL Connector

829023
New Contributor

I installed databricks-sql-connector in Pycharm.

Then i run the query below based on docs.

I refer this docs.

(https://docs.databricks.com/dev-tools/python-sql-connector.html)

==========================================

from databricks import sql

import os

with sql.connect(server_hostname = os.getenv("***"),

http_path = os.getenv("***"),

access_token = os.getenv("***")) as connection:

with connection.cursor() as cursor:

cursor.execute("SELECT * FROM default.diamonds LIMIT 2")

result = cursor.fetchall()

for row in result:

print(row)

=================================

However, I faced the error below.

(AttributeError: 'NoneType' object has no attribute 'startswith')

 File "C:\Users\MZC01-SSLEE\PycharmProjects\sqlconnector\venv\lib\site-packages\databricks\sql\__init__.py", line 50, in connect

  return Connection(server_hostname, http_path, access_token, **kwargs)

 File "C:\Users\MZC01-SSLEE\PycharmProjects\sqlconnector\venv\lib\site-packages\databricks\sql\client.py", line 156, in __init__

  auth_provider = get_python_sql_connector_auth_provider(

 File "C:\Users\MZC01-SSLEE\PycharmProjects\sqlconnector\venv\lib\site-packages\databricks\sql\auth\auth.py", line 84, in get_python_sql_connector_auth_provider

  hostname=normalize_host_name(hostname),

 File "C:\Users\MZC01-SSLEE\PycharmProjects\sqlconnector\venv\lib\site-packages\databricks\sql\auth\auth.py", line 77, in normalize_host_name

  maybe_scheme = "https://" if not hostname.startswith("https://") else ""

AttributeError: 'NoneType' object has no attribute 'startswith'

Could you give me some advice to solve this?

2 REPLIES 2

Debayan
Esteemed Contributor III
Esteemed Contributor III

Hi @Seungsu Lee​ , Could you please check the Database config settings , if there are multiple settings? Also, could you please check from where the DB credentials are called? (as far as I know it does not work with environment variables).

Hubert-Dudek
Esteemed Contributor III

It seems that one of your environment variables is incorrect. Please print them and compare them with the connection settings from the cluster or SQL warehouse endpoint.

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.