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: 

default auth: cannot configure default credentials

SankaraiahNaray
New Contributor II

 

I'm trying to use dbutils from WorkspaceClient and i tried to run this code from databricks notebook.

But i get this error

Error:

ValueError: default auth: cannot configure default credentials

 

Code:

from databricks.sdk import WorkspaceClient

w = WorkspaceClient()
d = w.dbutils.fs.ls('/')

for f in d:
   print(f.path)
1 REPLY 1

VZLA
Databricks Employee
Databricks Employee

To resolve the ValueError: default auth: cannot configure default credentials error when using dbutils from WorkspaceClient in a Databricks notebook, follow these steps:

  1. Ensure SDK Installation: Make sure the Databricks SDK for Python is installed. You can install it using the %pip magic command in a notebook cell (-U or --upgrade):

    1. %pip install -U databricks-sdk
  2. Restart Python: After installing the SDK, restart the Python environment to make the installed library available:

    1. dbutils.library.restartPython()
  3. Use Default Notebook Authentication: The Databricks notebook automatically handles authentication. You can directly use the WorkspaceClient without setting environment variables:

    1. from databricks.sdk import WorkspaceClient
      
      # Initialize WorkspaceClient
      w = WorkspaceClient()
      
      # List files in the specified directory
      d = w.dbutils.fs.ls('/')
      
      for f in d:
          print(f.path)

By following these steps, you should be able to resolve the authentication issue and run your code successfully within a Databricks notebook.

Some troubleshooting steps that can help you find the problem:

Print the environment variables, look for DATABRICKS_HOST and/or DATABRICKS_TOKEN.

import os
for key, value in os.environ.items():
    print(f'{key}: {value}')

 You may also share the full stacktrace here, I'm assuming there is more printed along with the "ValueError: default auth: cannot configure default credentials". Are you trying this in a Serverless or Classic Cluster? Which DBR release?

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