英文:
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 Contributor
、Storage Queue Data Message Processor
、Storage Queue Data Message Sender
或Storage 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论