cancel
Showing results for 
Search instead for 
Did you mean: 
Generative AI
Explore discussions on generative artificial intelligence techniques and applications within the Databricks Community. Share ideas, challenges, and breakthroughs in this cutting-edge field.
cancel
Showing results for 
Search instead for 
Did you mean: 

pop up when using databrics sql

kay0291
New Contributor

Hello, 

I am uning databricks sql to read from a unity catalog table locally on a python project using an azure sp client id and client secret
the connexion is successful however i have a pop up that asks me to connect to my azure env
is there a way to make this connexion without the pop up since we go through a client secret and a client id ?

this is my code 

from databricks import sql
from dotenv import load_dotenv
load_dotenv()



def get_conn():
    return sql.connect(
        server_hostname=os.getenv("DATABRICKS_HOST"),
        http_path=os.getenv("DATABRICKS_HTTP_PATH"),
        auth_type="azure-client-secret",
        azure_client_id=os.getenv("client_id"),
        azure_client_secret=os.getenv("client_secret"),
        azure_tenant_id=os.getenv("tenant_id"),
    )

with get_conn() as conn, conn.cursor() as cur:
        cur.execute("SELECT * FROM *")
        for row in cur.fetchall():
            print(row)


thank you !
1 REPLY 1

AbhaySingh
Databricks Employee
Databricks Employee

In your .env file, add:

  DATABRICKS_WORKSPACE_RESOURCE_ID=/subscriptions/your-sub-id/resourceGroups/your-rg/providers/Microsoft.Databricks/workspaces/your

  -workspace

 

  Alternative approaches if the popup persists:

 

  1. Use OAuth machine-to-machine (M2M) authentication (recommended for newer workspaces):

  auth_type="databricks-oauth"

  2. Ensure your service principal has proper permissions:

    - The SP needs to be added as a user in your Databricks workspace

    - Grant it appropriate permissions on Unity Catalog

  3. Try setting environment variable to disable browser-based auth:

  os.environ["DATABRICKS_AUTH_TYPE"] = "azure-client-secret"

 

  Let me know if the popup still appears after these changes!

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now