My python code uses AzureCliCredential() function, but it is giving error in running in Synapse/ADF/Databricks notebook .
My python code uses AzureCliCredential() function, but it is giving error in running in Synapse Workspace that your Azure Cli command not found on path .
I have tried using other function like DefaultAzureCredentials(), ClientSecretCredentials () also
ClientSecretCredential(
tenant_id="***",
client_id="***",
client_secret="***"
)
But above two functions are giving error in my local env too .
The only function that is working without any error is AzureCliCredentials() and I want my python code containing AzureCliCredentials function to get deploy on Synapse/ADF/Databricks and run successfully without showing error AzureCli Path not found, Please assist me for the same .
Azure Synapse Analytics
Azure Databricks
Azure Data Factory
-
phemanth 10,740 Reputation points • Microsoft Vendor
2024-07-19T09:15:27.3033333+00:00 @Utsav Mori
Thanks for the question and using MS Q&A platformIt seems like you're facing an issue with using
AzureCliCredential()
in Synapse Workspace, which is complaining about the Azure Cli command not being found on the path.You've tried using
DefaultAzureCredentials()
andClientSecretCredentials()
as well, but they're giving errors in your local environment too.The reason
AzureCliCredential()
is working without errors is that it uses the Azure CLI to authenticate, which is not the case with the other two credentials.To deploy your Python code containing
AzureCliCredentials
function to Synapse/ADF/Databricks and run it successfully without the AzureCli Path not found error, you need to ensure that the Azure CLI is installed and configured properly in your Synapse Workspace environment.Here's an example of how you can use
AzureCliCredential()
:from azure.identity import AzureCliCredential
I have tried my end and it has worked for me in synapse note book
with
ClientSecretCredentials()
is also working for me as shown belowand with
AzureCliCredential()
However, since you want to deploy your code to Synapse/ADF/Databricks, you might need to consider using
DefaultAzureCredential()
instead, as they are more suitable for managed environments.To use the
DefaultAzureCredential
function, follow these steps:Step 1: Install the
azure-identity
libraryIf you haven't already, install the
azure-identity
library using pip:pip install azure-identity
Step 2: Import the
DefaultAzureCredential
functionIn your Python code, import the
DefaultAzureCredential
function:from azure.identity import DefaultAzureCredential
Step 3: Create a credential object
Create a credential object using the
DefaultAzureCredential
function:credential = DefaultAzureCredential()
This will create a credential object that will try to authenticate using the methods mentioned above.
Step 4: Use the credential object
You can now use the credential object to authenticate with Azure services, such as Azure Storage, Azure Key Vault, or Azure Data Lake Storage.
For example, to use the credential object with Azure Storage:
from azure.storage.blob import BlobServiceClient blob_service_client = BlobServiceClient("https://<account_name>.blob.core.windows.net/", credential=credential)
Replace
<account_name> link
with the name of your Azure Storage account.If you're still facing issues, please provide more details about your environment and error logs, and I'll be happy to help you further.
Hope this helps. Do let us know if you any further queries.
-
Deleted
This comment has been deleted due to a violation of our Code of Conduct. The comment was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
-
Utsav Mori 20 Reputation points
2024-07-20T19:35:47.22+00:00 Hi ,
I am trying the same and it is not giving error till this point i.e:
from azure.identity import AzureCliCredential # from azure.identity import ClientSecretCredential from azure.identity import DefaultAzureCredential from pyapacheatlas.core import PurviewClient import json keywords = '*' # cred = AzureCliCredential() # print(cred) cred = DefaultAzureCredential() print(cred) client1 = PurviewCatalogClient(endpoint="account-name", credential=cred, logging_enable=True) print(client1)
but after writing the below line it is giving me DefaultAzureCredentials error, Below code is giving me error that is this response line:
body_input = { "keywords": keywords, "limit": 1, # "offset":l, #"filter": {"assetType": ""} } response = client1.discovery.query(search_request=body_input)
this above response line is giving me error:
Note : I can't use ClientSecretCredentials() because I can't access client_secret due to client side restriction.
Below is my overall code for your reference:
from azure.purview.catalog import PurviewCatalogClient from azure.identity import AzureCliCredential # from azure.identity import ClientSecretCredential from azure.identity import DefaultAzureCredential from pyapacheatlas.core import PurviewClient import json keywords = '*' # cred = AzureCliCredential() # print(cred) cred = DefaultAzureCredential() print(cred) client1 = PurviewCatalogClient(endpoint="account-name", credential=cred, logging_enable=True) print(client1) # client = PurviewClient( # account_name="", # authentication = cred # ) print(client) body_input = { "keywords": keywords, "limit": 1, # "offset":l, #"filter": {"assetType": ""} } response = client1.discovery.query(search_request=body_input) print(response)
-
phemanth 10,740 Reputation points • Microsoft Vendor
2024-08-05T10:01:55.99+00:00 The error you're encountering is likely due to the fact that
DefaultAzureCredential()
is not able to find a suitable authentication method to use.Since you're unable to use
ClientSecretCredential()
due to client-side restrictions, let's try to troubleshoot the issue withDefaultAzureCredential()
.Here are a few things you can try:
- Make sure that the Azure CLI is installed and configured properly on your machine. You can check this by running
az --version
in your terminal. - Ensure that you're logged in to the Azure CLI using the correct account. You can check this by running
az account show
in your terminal. - Try setting the
AZURE_TENANT_ID
andAZURE_CLIENT_ID
environment variables to the correct values for your Azure Purview account. - If you're running your code in a managed environment, ensure that the environment has the necessary permissions to access Azure Purview.
import logging from azure.purview.catalog import PurviewCatalogClient from azure.identity import DefaultAzureCredential from pyapacheatlas.core import PurviewClient import json # Set up logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) keywords = '*' # Create a credential object cred = DefaultAzureCredential() logger.info("Created credential object") # Create a Purview client object client1 = PurviewCatalogClient(endpoint="account-name", credential=cred, logging_enable=True) logger.info("Created Purview client object") # Create a search request body body_input = { "keywords": keywords, "limit": 1, # "offset":l, #"filter": {"assetType": ""} } try: # Send the search request response = client1.discovery.query(search_request=body_input) logger.info("Received response") print(response) except Exception as e: logger.error("Error sending search request: %s", e)
This code will log some additional information to help you troubleshoot the issue. You can adjust the logging level to
DEBUG
if you need more detailed information. - Make sure that the Azure CLI is installed and configured properly on your machine. You can check this by running
-
phemanth 10,740 Reputation points • Microsoft Vendor
2024-08-07T06:07:36.19+00:00 @Utsav Mori We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet. In case if you have any resolution please do share that same with the community as it can be helpful to others. Otherwise, will respond with more details and we will try to help.
-
phemanth 10,740 Reputation points • Microsoft Vendor
2024-08-09T13:59:20.79+00:00 @Utsav Mori just checking back to see if you have a resolution yet. In case if you have any resolution please do share that same with the community as it can be helpful to others. Otherwise, will respond with more details and we will try to help.
Sign in to comment