Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.37k stars 2.71k forks source link

'AttributeError: module 'azure.core.pipeline.policies' has no attribute 'SensitiveHeaderCleanupPolicy''. #34880

Open hchitnen opened 3 months ago

hchitnen commented 3 months ago

Describe the bug The above error is throwing up when running the below code. To be specific, this happens when calling the 'ImageAnalysisClient' I have the azure-core 1.30 version (the latest) but still receiving the error.

Code To Reproduce

import pandas as pd import os from azure.ai.vision.imageanalysis import ImageAnalysisClient from azure.ai.vision.imageanalysis.models import VisualFeatures from azure.core.credentials import AzureKeyCredential import numpy as np

def azureml_main(dataframe1 = None, dataframe2 = None):

# Execution logic goes here
print(f'Input pandas.DataFrame #1: {dataframe1}')

client = ImageAnalysisClient(
endpoint='https://ipmicro-ocr.cognitiveservices.azure.com/',
credential=AzureKeyCredential('<redacted>')
)

Get a caption for the image.

for i in range(0,5):
    result = client.analyze_from_url(
        image_url=products['ItemDocumentValue'][i],
        visual_features=[VisualFeatures.CAPTION, VisualFeatures.READ, VisualFeatures.TAGS],
        gender_neutral_caption=True,  # Optional (default is False)
    )

    print("Image analysis results:")
    # Print caption results to the console
    print(" Caption:")
    if result.caption is not None:
        print(f"   '{result.caption.text}', Confidence {result.caption.confidence:.4f}")
        products['Caption'][i] = result.caption.text

    if result.tags is not None:
        print(" Tags:")
        temp_tags=[]
        for tag in result.tags.list:
            print(f"   '{tag.name}', Confidence {tag.confidence:.4f}")
            temp_tags.append(tag.name)
        products['Tags'][i] = temp_tags  

    # Print text (OCR) analysis results to the console
    print(" Read:")
    if result.read is not None:
        temp_des=''
        try:
            for line in result.read.blocks[0].lines:
                temp_des = temp_des + ' '+ line.text
            products['Description'][i] = temp_des
        except:
            np.nan
return products,

Exact Error:

---------- Start of error message from Python interpreter ---------- Got exception when invoking script at line 22 in function azureml_main: 'AttributeError: module 'azure.core.pipeline.policies' has no attribute 'SensitiveHeaderCleanupPolicy''. ---------- End of error message from Python interpreter ----------

xiangyan99 commented 3 months ago

Thanks for reaching out.

Could you run pip list and share the output?

github-actions[bot] commented 3 months ago

Hi @hchitnen. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

hchitnen commented 3 months ago

Thanks for reaching out.

Could you run pip list and share the output?

Hi, I am using designer in Azure ML studio to build a pipeline. I am importing all the libraries in a zip folder.

i have followed the steps suggested by an user on stackoverflow. please find attached the screenshot for your reference.

image

Following the above steps, Here is how I am doing it for my project.

image

in the above, the "execute python script' has the code that I have shared earlier. And "ocr-v2" is the zip folder that has all the libraries. I have also specifically looked for "SensitiveHeaderCleanupPolicy" and it is included in the libraries. please find attached the screenshot.

image
hchitnen commented 3 months ago

Please do let me know in case any further information is needed from my end.

hchitnen commented 3 months ago

Hi, any update? Please do let me know in case any further information is needed from my end.

dargilco commented 3 months ago

@hchitnen do the samples in this link work for you using the same credentials you used above, and latest image analysis client library 1.0.0b2)? https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/vision/azure-ai-vision-imageanalysis/samples

Same for the code your shared in "Get a caption for the image." - does it work for you in a terminal window? (not as uploaded ZIP package to Azure ML studio).

Just want to make sure basic functionality works for you in isolation, before looping in other folks to understand what's unique about your Azure ML package.

newhardwarefound commented 2 months ago

I am having the same issue on AzureML Jupyter notebook's default environments. The interesting thing is I can do from azure.core.pipeline.policies._sensitive_header_cleanup_policy import SensitiveHeaderCleanupPolicy without any error but not from azure.core.pipeline.policies import SensitiveHeaderCleanupPolicy

What worked for me? I pip uninstall every package in the python 3.10 environment. Then switch to python 3.8 environment. pip install all required packages and it works magically. I assume there is some package dependency conflict in AzureML Jupyter notebook's environments. They have a lot of outdated packages there.

pacozaa commented 2 months ago

That isn't nice. Some libraries need Python 3.10 like Unsloth. It doesn't make any sense that this error has not been fix given the cost of GPU VM.

noe-sautel commented 1 month ago

Hello @dargilco, any update on this? I have a similar issue

pranav-thampi-numerator commented 1 month ago

I am getting the same error while trying the create a cron-job-schedule using az ml schedule create --file {file_name} --debug --resource-group {rsg_name} --workspace-name {workspace-name}

here is the error:

Traceback (most recent call last): File "/agent/_work/_temp/.azclitask/cliextensions/ml/azext_mlv2/manual/vendored_curated_sdk/azure/ai/ml/operations/_operation_orchestrator.py", line 279, in _get_code_asset_arm_id code_asset = self._code_assets.create_or_update(code_asset) # type: ignore[attr-defined] File "/agent/_work/_temp/.azclitask/cliextensions/ml/azext_mlv2/manual/vendored_curated_sdk/azure/ai/ml/_telemetry/activity.py", line 288, in wrapper return f(*args, **kwargs) File "/agent/_work/_temp/.azclitask/cliextensions/ml/azext_mlv2/manual/vendored_curated_sdk/azure/ai/ml/operations/_code_operations.py", line 212, in create_or_update raise ex File "/agent/_work/_temp/.azclitask/cliextensions/ml/azext_mlv2/manual/vendored_curated_sdk/azure/ai/ml/operations/_code_operations.py", line 160, in create_or_update code, _ = _check_and_upload_path( File "/agent/_work/_temp/.azclitask/cliextensions/ml/azext_mlv2/manual/vendored_curated_sdk/azure/ai/ml/_artifacts/_artifact_utilities.py", line 502, in _check_and_upload_path uploaded_artifact = _upload_to_datastore( File "/agent/_work/_temp/.azclitask/cliextensions/ml/azext_mlv2/manual/vendored_curated_sdk/azure/ai/ml/_artifacts/_artifact_utilities.py", line 387, in _upload_to_datastore artifact = upload_artifact( File "/agent/_work/_temp/.azclitask/cliextensions/ml/azext_mlv2/manual/vendored_curated_sdk/azure/ai/ml/_artifacts/_artifact_utilities.py", line 240, in upload_artifact storage_client = get_storage_client(credential=None, storage_account=None, account_url=sas_uri) File "/agent/_work/_temp/.azclitask/cliextensions/ml/azext_mlv2/manual/vendored_curated_sdk/azure/ai/ml/_utils/_storage_utils.py", line 177, in get_storage_client return client_builders[storage_type](credential, container_name, account_url) File "/agent/_work/_temp/.azclitask/cliextensions/ml/azext_mlv2/manual/vendored_curated_sdk/azure/ai/ml/_utils/_storage_utils.py", line 151, in <lambda> DatastoreType.AZURE_BLOB: lambda credential, container_name, account_url: BlobStorageClient( File "/agent/_work/_temp/.azclitask/cliextensions/ml/azext_mlv2/manual/vendored_curated_sdk/azure/ai/ml/_artifacts/_blob_storage_helper.py", line 50, in __init__ self.service_client = BlobServiceClient(account_url=account_url, credential=credential) File "/agent/_work/_temp/.azclitask/cliextensions/ml/azure/storage/blob/_blob_service_client.py", line 141, in __init__ self._client = AzureBlobStorage(self.url, base_url=self.url, pipeline=self._pipeline) File "/agent/_work/_temp/.azclitask/cliextensions/ml/azure/storage/blob/_generated/_azure_blob_storage.py", line 72, in __init__ policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None, AttributeError: module 'azure.core.pipeline.policies' has no attribute 'SensitiveHeaderCleanupPolicy'

Here are the package versions: azure-cli 2.51.0 *

core 2.51.0 * telemetry 1.1.0

Dependencies: msal 1.24.0b1 azure-mgmt-resource 23.1.0b2

pranav-thampi-numerator commented 1 month ago

It worked for me by upgarding the version of azure-cli https://github.com/Azure/azure-cli/issues/28649

hchitnen commented 1 month ago

I deleted the 'SensitiveHeaderCleanupPolicy' class dependency from the package and it worked for me. although, not sure about the ramifications of this action. Worked for my use case.