Azure QueueClient Python 无法使用 DefaultAzureCredential

huangapple go评论73阅读模式
英文:

Azure QueueClient Python can't use DefaultAzureCredential

问题

I'm using DefaultAzureCredential() from azure.identity to get credential and use it to establish TableServiceClient (azure.data.table) connection. It works. If I am trying to do the same for QueueClient (azure.storage.queue), I'm getting following error. As far as I understand documentation, it should be possible to use DefaultAzureCredential() for that.

[2023-05-06T08:40:40.331Z] Response status: 403
Response headers:
    'Content-Length': '279'
    'Content-Type': 'application/xml'
    'Server': 'Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0'
    'x-ms-request-id': '30a41a1b-a003-0004-71f6-7f25a6000000'
    'x-ms-client-request-id': 'adedb50b-ebe9-11ed-b983-001a7dda7113'
    'x-ms-version': 'REDACTED'
    'x-ms-error-code': 'REDACTED'
    'Date': 'Sat, 06 May 2023 08:40:39 GMT'

I'm connecting in the following way. If I switch credential with a storage account key, it works.

credential = DefaultAzureCredential()
queue_service_client = QueueClient(
  account_url = os.environ["STORAGE_ENDPOINT_QUEUE"],
  credential=credential,
  queue_name  = "smsnotification"
  )

def pushNotifyToQueue(queue_service_client, playerId):
    logging.info(f"Push notify to queue")
    try:
        response = queue_service_client.send_message("m")
        logging.info(f"Print response from queue {response}")
    except:
        logging.info(f"Something goes wrong when pushing notify to queue")
        #TODO use ErrorName

I was trying to use Storage Account Key, and it works. DefaultAzureCredential is also working for TableServiceClient but not for Queue.

英文:

I'm using DefaultAzureCredential() from azure.identity to get credential and use it to establish TableServiceClient (azure.data.table) connection. It works.
If I am trying to do the same for QueueClient (azure.storage.queue), I'm getting following error.
As far as I understand documentation, it should be possible to use DefailtAzureCredential() for that.

[2023-05-06T08:40:40.331Z] Response status: 403
Response headers:
    'Content-Length': '279'
    'Content-Type': 'application/xml'
    'Server': 'Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0'
    'x-ms-request-id': '30a41a1b-a003-0004-71f6-7f25a6000000'
    'x-ms-client-request-id': 'adedb50b-ebe9-11ed-b983-001a7dda7113'
    'x-ms-version': 'REDACTED'
    'x-ms-error-code': 'REDACTED'
    'Date': 'Sat, 06 May 2023 08:40:39 GMT'

I'm connecting in following way. If I switch credential with storage account key, it works.

credential = DefaultAzureCredential()
queue_service_client = QueueClient(
  account_url = os.environ["STORAGE_ENDPOINT_QUEUE"],
  credential=credential,
  queue_name  = "smsnotification"
  )

def pushNotifyToQueune(queue_service_client, playerId):
    logging.info(f"Push notify to queune")
    try:
        response = queue_service_client.send_message("m")
        logging.info(f"Print response form queune {response}")
    except:
        logging.info(f"Something goes wrong when pusing notify to queune")
        #TODO use ErrorName

I were trying to use Storage Account Key and it works. DefaultAzureCredential is also working for TableServiceClient but not for Queue.

答案1

得分: 2

请确保您的用户帐户分配了与存储队列相关的RBAC角色之一。您的用户帐户必须分配一个或多个Storage Queue Data ContributorStorage Queue Data Message ProcessorStorage Queue Data Message SenderStorage Queue Data Reader 角色,具体取决于您的需求。

英文:

Please make sure that your user account is assigned one of the Storage Queue related RBAC roles. Your user account must be assigned one or more of Storage Queue Data Contributor, Storage Queue Data Message Processor, Storage Queue Data Message Sender, or Storage Queue Data Reader roles depending on your requirements.

huangapple
  • 本文由 发表于 2023年5月6日 16:54:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76187997.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定