python - 使用 Azure 存储模拟器创建 Python `BlobClient.from_blob_url`?
问题描述
我正在尝试在以下场景中使用 Azure 存储模拟器:
- Blob 上传到模拟容器
- 上传 Blob 时创建的模拟事件网格消息
- 模拟队列存储接收事件网格消息
- 从队列存储消息触发本地运行的 Azure 函数
问题:
1 以上。工作正常(模拟器已启动并运行)
2 以上。是手动的,我不想下载和使用第三方事件网格模拟器。
- 相反,我使用上传的 blob 的名称手动创建事件网格消息
{
"id": "<long-guid>",
"data": {
"api": "FlushWithClose",
"clientRequestId": "<long-guid>",
"requestId": "<long-guid>",
"eTag": "0x8D9430B96888008",
"contentType": "application/octet-stream",
"contentLength": 4633473584,
"contentOffset": 0,
"blobType": "BlockBlob",
"blobUrl": "http://127.0.0.1:10000/devstoreaccount1/test/710520200429.csv",
"url": "http://127.0.0.1:10000/devstoreaccount1/test/710520200429.csv",
"sequencer": "0000000000000000000000000000933600000000000023c7",
"identity": "<long-guid>",
"storageDiagnostics": {
"batchId": "<long-guid>"
}
},
"topic": "/subscriptions/<long-guid>/resourceGroups/DEV/providers/Microsoft.Storage/storageAccounts/fa00001dev",
"subject": "/blobServices/default/containers/test/blobs/710520200429.csv",
"event_type": "Microsoft.Storage.BlobCreated"
}
- 然后在 Emulator Queue Storage 中新建一条消息并粘贴进去(基本上 3. 上面)
4 以上。函数触发但无法执行以下代码:
credentials = DefaultAzureCredential()
def create_blob_client(credentials):
try:
blob_client = BlobClient.from_blob_url(eg_msg_json['data']['blobUrl'], credentials, max_single_get_size = 256*1024*1024, max_chunk_get_size = 128*1024*1024)
logging.info(f'####### Successfully created BlobClient #######')
except:
logging.error(f'####### Failed to create BlobClient #######')
logging.error(f'####### Blob URL: {eg_msg_json["data"]["blobUrl"]} #######')
return blob_client
- 因为要么 不正确
blobUrl
,要么不允许从模拟器创建。http://127.0.0.1:10000/devstoreaccount1/test/710520200429.csv
BlobClient.from_blob_url
BlobClient
错误:
[2021-07-31T00:23:01.397Z] ManagedIdentityCredential will use IMDS
[2021-07-31T00:23:01.405Z] Executed 'Functions.fa00003' (Failed, Id=55f8ce9e-08b5-41e2-bd61-d753da0d72e1, Duration=47ms)
[2021-07-31T00:23:01.410Z] System.Private.CoreLib: Exception while executing function: Functions.fa00003. System.Private.CoreLib: Result: Failure
Exception: ValueError: Invalid tenant id provided. You can locate your tenant id by following the instructions here: https://docs.microsoft.com/partner-center/find-ids-and-domain-names
Stack: File "C:\Users\test\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.8\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 398, in _handle__invocation_request
call_result = await self._loop.run_in_executor(
File "C:\Users\test\AppData\Local\Programs\Python\Python38\lib\concurrent\futures\thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "C:\Users\test\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.8\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 602, in _run_sync_func
return ExtensionManager.get_sync_invocation_wrapper(context,
File "C:\Users\test\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.8\WINDOWS\X64\azure_functions_worker\extension.py", line 215, in _raw_invocation_wrapper result = function(**args)
File "C:\Users\test\Desktop\git\Azure\Functions\fa00003\fa00003\__init__.py", line 132, in main
credentials = DefaultAzureCredential()
File "C:\Users\test\Desktop\git\Azure\Functions\fa00003\.venv\lib\site-packages\azure\identity\_credentials\default.py", line 123, in __init__
credentials.append(VisualStudioCodeCredential(tenant_id=vscode_tenant_id))
File "C:\Users\test\Desktop\git\Azure\Functions\fa00003\.venv\lib\site-packages\azure\identity\_credentials\vscode.py", line 43, in __init__
validate_tenant_id(self._tenant_id)
File "C:\Users\test\Desktop\git\Azure\Functions\fa00003\.venv\lib\site-packages\azure\identity\_internal\__init__.py", line 40, in validate_tenant_id
raise ValueError(
.
谁能告诉我这里哪个是正确的?
解决方案
推荐阅读
- python - 从 Django 表单调用 Django-Rest API
- java - 升级到 2.x 时 org.refcodes.console.ConsoleSugar 缺少 switsh 和 helpSwitch 方法
- nginx - AWS EC2 上的 Flask-SocketIO 502 错误,带有 [CRITICAL] 工作线程超时
- ag-grid - 当 autoGroupColumnDef 更改时,AgGridReact 组件不更新
- python - 如何使用字典语法调用函数?
- cython - Texgenpack Wrapper - 编译问题
- css - 如何正确匹配我的子元素与其父元素的边界半径
- php - 隐藏具有相同“角色”的用户的数据
- python - 我安装了 python 但我的 Scripts 文件夹是空的
- python - Discord.py purge 命令中的人员列表和已删除消息的数量