exception when create azure ml data asset

dp600 0 Reputation points
2025-01-19T22:11:15.92+00:00

Hi,

This is my code to create a data asset:

# This section of code authenticates to an Azure Key Vault Using the Client Secret Credentials
credentials = ClientSecretCredential(client_id=client_id, client_secret=client_secret,tenant_id=tenant_id) 
ml_client = MLClient(
    credentials, subs_id, res_group
)
# Verify that the handle works correctly.
ws = ml_client.workspaces.get(ws_name)
print(ws.location, ":", ws.resource_group)

my_path = "./data/default_of_credit_card_clients.csv"
# Check if the file exists
if os.path.exists(my_path):
   print("The file exists.")

# set the version number of the data asset
v1 = "initial"
ds_name="credit-card"
my_data = Data(name=ds_name,version=v1,description="Credit card data",path=my_path,type=AssetTypes.URI_FILE,)

## create data asset if it doesn't already exist:
try:
    data_asset = ml_client.data.get(name=ds_name, version=v1)
    print(
        f"Data asset already exists. Name: {my_data.name}, version: {my_data.version}"
    )
except:
    print("came here 2: " + ml_client.workspaces.get(ws_name).resource_group)
    ml_client.data.create_or_update(my_data)
    #print(f"Data asset created. Name: {my_data.name}, version: {my_data.version}")

But I get the following exception in create_or_update:\

Traceback (most recent call last):
  File "/home/nishal/Desktop/code/RosenPrep/hello2.py", line 52, in <module>
    data_asset = ml_client.data.get(name=ds_name, version=v1)
  File "/home/nishal/.local/lib/python3.10/site-packages/azure/ai/ml/_telemetry/activity.py", line 292, in wrapper
    return f(*args, **kwargs)
  File "/home/nishal/.local/lib/python3.10/site-packages/azure/ai/ml/operations/_data_operations.py", line 276, in get
    data_version_resource = self._get(name, version)
  File "/home/nishal/.local/lib/python3.10/site-packages/azure/ai/ml/operations/_data_operations.py", line 205, in _get
    else self._operation.get(
  File "/home/nishal/.local/lib/python3.10/site-packages/azure/core/tracing/decorator.py", line 105, in wrapper_use_tracer
    return func(*args, **kwargs)
  File "/home/nishal/.local/lib/python3.10/site-packages/azure/ai/ml/_restclient/v2023_04_01_preview/operations/_data_versions_operations.py", line 467, in get
    request = build_get_request(
  File "/home/nishal/.local/lib/python3.10/site-packages/azure/ai/ml/_restclient/v2023_04_01_preview/operations/_data_versions_operations.py", line 149, in build_get_request
    "workspaceName": _SERIALIZER.url("workspace_name", workspace_name, 'str', pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]{2,32}$'),
  File "/home/nishal/.local/lib/python3.10/site-packages/msrest/serialization.py", line 652, in url
    output = self.serialize_data(data, data_type, **kwargs)
  File "/home/nishal/.local/lib/python3.10/site-packages/msrest/serialization.py", line 760, in serialize_data
    raise ValueError("No value for given attribute")
ValueError: No value for given attribute

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/nishal/Desktop/code/RosenPrep/hello2.py", line 58, in <module>
    ml_client.data.create_or_update(my_data)
  File "/home/nishal/.local/lib/python3.10/site-packages/azure/ai/ml/_telemetry/activity.py", line 292, in wrapper
    return f(*args, **kwargs)
  File "/home/nishal/.local/lib/python3.10/site-packages/azure/ai/ml/operations/_data_operations.py", line 425, in create_or_update
    raise ex
  File "/home/nishal/.local/lib/python3.10/site-packages/azure/ai/ml/operations/_data_operations.py", line 367, in create_or_update
    data, _ = _check_and_upload_path(
  File "/home/nishal/.local/lib/python3.10/site-packages/azure/ai/ml/_artifacts/_artifact_utilities.py", line 506, in _check_and_upload_path
    uploaded_artifact = _upload_to_datastore(
  File "/home/nishal/.local/lib/python3.10/site-packages/azure/ai/ml/_artifacts/_artifact_utilities.py", line 384, in _upload_to_datastore
    artifact = upload_artifact(
  File "/home/nishal/.local/lib/python3.10/site-packages/azure/ai/ml/_artifacts/_artifact_utilities.py", line 240, in upload_artifact
    datastore_info = get_datastore_info(datastore_operation, datastore_name)
  File "/home/nishal/.local/lib/python3.10/site-packages/azure/ai/ml/_artifacts/_artifact_utilities.py", line 99, in get_datastore_info
    datastore = operations.get(name) if name else operations.get_default()
  File "/home/nishal/.local/lib/python3.10/site-packages/azure/ai/ml/_telemetry/activity.py", line 292, in wrapper
    return f(*args, **kwargs)
  File "/home/nishal/.local/lib/python3.10/site-packages/azure/ai/ml/operations/_datastore_operations.py", line 155, in get
    datastore_resource = self._operation.get(
  File "/home/nishal/.local/lib/python3.10/site-packages/azure/core/tracing/decorator.py", line 105, in wrapper_use_tracer
    return func(*args, **kwargs)
  File "/home/nishal/.local/lib/python3.10/site-packages/azure/ai/ml/_restclient/v2024_07_01_preview/operations/_datastores_operations.py", line 496, in get
    request = build_get_request(
  File "/home/nishal/.local/lib/python3.10/site-packages/azure/ai/ml/_restclient/v2024_07_01_preview/operations/_datastores_operations.py", line 147, in build_get_request
    "workspaceName": _SERIALIZER.url("workspace_name", workspace_name, 'str', pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]{2,32}$'),
  File "/home/nishal/.local/lib/python3.10/site-packages/msrest/serialization.py", line 652, in url
    output = self.serialize_data(data, data_type, **kwargs)
  File "/home/nishal/.local/lib/python3.10/site-packages/msrest/serialization.py", line 760, in serialize_data
    raise ValueError("No value for given attribute")
ValueError: No value for given attribute

Please can anyone advise?

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
3,086 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 28,066 Reputation points
    2025-01-20T09:29:14.3633333+00:00

    Based on the error message, it is either one or more required attributes are missing or they are not formatted correctly in your code, particularly in the workspace name or datastore configuration.

    The workspace_name attribute is missing or improperly formatted when serializing the URL for the request.

    The create_or_update method is attempting to upload the artifact to a datastore, but it encounters an issue when trying to retrieve the default datastore or the specified datastore.

    While you are verifying that the file exists locally, issues with the path or the ability to resolve it relative to the workspace might still arise.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.