如何对 Azure Blob 存储的 fsspec 进行身份验证

Val*_*ecz 5 filesystems django azure django-rest-framework azure-blob-storage

从 django REST API 视图中,我尝试访问存储在 azure 存储 blob 中的文件。我想打开它而不将其下载到文件中,如此处所示。读取访问权限就足够了。

为此,我这样勾勒出我的观点:

import os
from fsspec.implementations.http import HTTPFileSystem

@api_view()
def my_view(request):
    url = "https://storageaccount.blob.core.windows.net/container/"
    filename = "file.f"
    fs = HTTPFileSystem(
        container_name=os.environ["AZURE_STORAGE_CONTAINER"],
        storage_options={
            "account_name": os.environ["AZURE_STORAGE_ACCOUNT"],
            "account_key": os.environ["AZURE_STORAGE_KEY"],
        },
    )
    with fs.open(url + filename, "r") as fobj:
        ds = somehow.open_dataset(fobj)

    return Response({"message": "Data manipulated"}, status=200)
Run Code Online (Sandbox Code Playgroud)

这会给出 FileNotFoundError。

我的问题是:

  • 使用天蓝色的 blob 存储是否可以实现这一点?如果不是,最接近的是什么?
  • 我如何验证 HTTPFileSystem?我觉得我或多或少地编造了这些关键字,但无法找到任何有关它的信息......

Ric*_*ell 1

我们还花了一段时间才弄清楚如何从 fsspec 访问 Azure Blob 存储,因此将其记录在此处。

在 Azure 门户中,在存储帐户级别(而不是容器级别),我们单击“网络+安全”部分中的“访问密钥”,并创建了一个account_keyconnection_string

我们创建了一个$HOME/.env包含这些密钥对值的文件:

account_key=xxxxxx
connection_string=xxxxxxx
Run Code Online (Sandbox Code Playgroud)

然后在Python中,我们做了:

account_key=xxxxxx
connection_string=xxxxxxx
Run Code Online (Sandbox Code Playgroud)