最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Azure AI - Getting permission denied error after granting permission to the role - Stack Overflow

programmeradmin1浏览0评论

I am trying to access the Azure Image analysis client with below configuration

i created the application and added the role 'Cognitive Services Custom Vision Contributor' to the application

but when i try to access the image client, i am getting PermissionDenied error

tenant_id = tent_id
client_id = app_client_id
client_secret = secret_value

credential = ClientSecretCredential(
    tenant_id=tenant_id,
    client_id=client_id,
    client_secret=client_secret
)
end_point = '/'

client = ImageAnalysisClient(
    endpoint=end_point,
    credential=credential,
)

but getting following error

azure.core.exceptions.ClientAuthenticationError: (PermissionDenied) Principal does not have access to API/Operation.
Code: PermissionDenied
Message: Principal does not have access to API/Operation.

I am trying to access the Azure Image analysis client with below configuration

i created the application and added the role 'Cognitive Services Custom Vision Contributor' to the application

but when i try to access the image client, i am getting PermissionDenied error

tenant_id = tent_id
client_id = app_client_id
client_secret = secret_value

credential = ClientSecretCredential(
    tenant_id=tenant_id,
    client_id=client_id,
    client_secret=client_secret
)
end_point = 'https://azureaicomputervision.cognitiveservices.azure.com/'

client = ImageAnalysisClient(
    endpoint=end_point,
    credential=credential,
)

but getting following error

azure.core.exceptions.ClientAuthenticationError: (PermissionDenied) Principal does not have access to API/Operation.
Code: PermissionDenied
Message: Principal does not have access to API/Operation.

Share Improve this question asked Feb 7 at 2:55 Hari UmeshHari Umesh 1 New contributor Hari Umesh is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 1
  • For Image Analysis, recommended role is "Cognitive Services User". Try adding Cognitive Services User. – Suresh Chikkam Commented Feb 7 at 3:35
Add a comment  | 

1 Answer 1

Reset to default 0

You mentioned assigning "Cognitive Services Custom Vision Contributor", but for Image Analysis, the recommended role is "Cognitive Services User"

  • Open Microsoft Entra ID now, click on App registrations go to API permissions click Add a permission. Select Azure AI Services and Delegated permissions. Add CognitiveServices.ComputerVision. click Grant admin consent.

Install pip install azure-ai-vision azure-identity python Library.

Code:

from azure.identity import ClientSecretCredential
from azure.ai.vision.imageanalysis import ImageAnalysisClient

# Replace with your Microsoft Entra ID details
TENANT_ID = "your-tenant-id"
CLIENT_ID = "your-client-id"
CLIENT_SECRET = "your-client-secret"
ENDPOINT = "https://your-resource-name.cognitiveservices.azure.com/"

# Authenticate using Microsoft Entra ID
credential = ClientSecretCredential(
    tenant_id=TENANT_ID,
    client_id=CLIENT_ID,
    client_secret=CLIENT_SECRET
)

# Initialize Image Analysis Client
client = ImageAnalysisClient(
    endpoint=ENDPOINT,
    credential=credential,
)

# Test authentication
token = credential.get_token("https://cognitiveservices.azure.com/.default")
print("Access Token:", token.token)  # Should print a valid token
发布评论

评论列表(0)

  1. 暂无评论