【问题标题】:Access Azure Blob using Python without Azure Storage Blob package在没有 Azure 存储 Blob 包的情况下使用 Python 访问 Azure Blob
【发布时间】:2021-05-28 11:09:19
【问题描述】:

我需要使用 Python 将 JSON 文件上传到 Azure blob,使用以下代码:

from azure.storage.blob import BlobClient

blob = BlobClient(account_url=ACCOUNT_URL,
                  container_name=CONTAINER_NAME,
                  blob_name = folder1/folder2/sample.json,
                  credential=CREDENTIAL)

blob.upload_blob(json.dumps(sample_json),overwrite=True)

此代码运行良好。 唯一的问题是,包 azure.storage.blob 安装了 chardet 包,它是 LGPL 许可的,它不适合我的项目。有没有其他方法可以在不使用上述包的情况下将数据上传到 Azure 上的 blob?

【问题讨论】:

    标签: python-3.x azure


    【解决方案1】:

    SDK 只是Azure Storage REST API 的包装。如果您无法使用 SDK,您可以编写自己的代码来使用 REST API。

    对于上传 blob,REST API 操作将是 Put Blob: https://docs.microsoft.com/en-us/rest/api/storageservices/put-blob

    鉴于 SDK 是开源的,您可以查看 SDK 代码并了解 SDK 中如何使用 REST API。您可以在此处找到源代码:https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob/azure/storage/blob

    【讨论】:

      猜你喜欢
      • 2022-06-11
      • 2013-01-28
      • 1970-01-01
      • 2013-12-04
      • 2020-06-03
      • 2021-12-18
      • 2021-11-19
      • 2012-09-30
      • 1970-01-01
      相关资源
      最近更新 更多