cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
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
Databricks Employee
Databricks Employee

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.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group