- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2025 01:03 AM
Hi,
I am working on Databricks workspace setup on AWS and trying to use Service Principal to execute API calls (CI/CD) deployment through Bitbucket. So I created secret for the service principal and trying to test the token. The test failed with below error:
Using token: doseXXXXXXXXXXXXXXXXXXX calling request get Error 401: {"error_code":401,"message":"Credential was not sent or was of an unsupported type for this API."}
I changed the token to PAT and the script worked fine. Can you please confirm what the issue here. The service principal looks fine as I tested running DLT pipelines successfully via service principal.
Here is the script for your reference. This code list the clusters in the workspace:
import os
import requests
# Fetch the token from environment variables
databricks_token = 'doseXXXXXXXXXXXXXXXXXXX'
if not databricks_token:
raise ValueError("DATABRICKS_TOKEN is not set.")
print(f"Using token: {databricks_token}")
# Define the API endpoint and headers
databricks_instance = "https://xxx.databricks.com" # Replace with your Databricks workspace URL
url = f"{databricks_instance}/api/2.0/clusters/list"
headers = {"Authorization": f"Bearer {databricks_token}"}
# Make the API call
print("calling request get")
response = requests.get(url, headers=headers)
# Check response
if response.status_code == 200:
print("Success:", response.json())
# display(response.json())
else:
print(f"Error {response.status_code}: {response.text}")