【问题标题】:Azure blob error :The specified blob does not exist, But Blob is presentAzure Blob 错误:指定的 Blob 不存在,但 Blob 存在
【发布时间】:2021-03-26 16:24:57
【问题描述】:

运行我的 azure 函数后出现错误,该函数用于读取 azure blob 存储。

错误是

      ID 0dad768d-36d4-4c1a-85ae-2a5122533b3c
fail: Function.processor.User[0]
      Traceback (most recent call last):
        File "/usr/local/lib/python3.8/site-packages/azure/storage/blob/_download.py", line 360, in _initial_request
          location_mode, response = self._clients.blob.download(
        File "/usr/local/lib/python3.8/site-packages/azure/storage/blob/_generated/operations/_blob_operations.py", line 186, in download
          map_error(status_code=response.status_code, response=response, error_map=error_map)
        File "/usr/local/lib/python3.8/site-packages/azure/core/exceptions.py", line 102, in map_error
          raise error
      azure.core.exceptions.ResourceNotFoundError: Operation returned an invalid status 'The specified blob does not exist.'
  

我访问文件的python代码是

from azure.storage.filedatalake import DataLakeFileClient  

def get_file(self, file_path: str) -> Union[str, bytes, bytearray]:
    """Retrieve the file content of a file stored in the Data Lake
    
    Args:
        file_path (str): The path to the file
    
    Returns:
        Union[str, bytes, bytearray]: File content
    
    Raises:
        Exception: Description
    """

    try:
        file = DataLakeFileClient(
            account_url=self.account_url,
            credential=self.account_key,
            file_system_name=self.fs_name,
            file_path=file_path)
        return bytes(file.download_file().readall())
    except ResourceNotFoundError as e:
        raise Exception("No such file")

任何人都知道这是什么解决方案

BLOB


【问题讨论】:

  • 而且代码看起来不完整。
  • 编辑了内容
  • 截图显示了目录,里面有blob吗?
  • datalake 是 blob
  • 你能通过我提供的代码读取blob内容吗?

标签: azure azure-blob-storage azure-data-lake-gen2


【解决方案1】:

示例代码(请确保 'myfile' 存在。):

from azure.storage.filedatalake import DataLakeServiceClient 
connect_str = "DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=xxxxxx;EndpointSuffix=core.windows.net"
datalake_service_client = DataLakeServiceClient.from_connection_string(connect_str)
myfilesystem = "test"
myfolder     = "test"
myfile       = "FileName.txt"

file_system_client = datalake_service_client.get_file_system_client(myfilesystem)            
directory_client = file_system_client.create_directory(myfolder)         
directory_client = file_system_client.get_directory_client(myfolder)

file_client = directory_client.get_file_client(myfile)
print(file_client.download_file().readall())

【讨论】:

  • @galiylama 你可以根据这个尝试看看有没有错误。
  • file_system_client.create_directory(myfolder) is it necessary.folder 已经存在了吗?
  • 在这个方法中 datalake_service_client = DataLakeServiceClient.from_connection_string(connect_str) 文件路径和文件系统应该定义
  • @galiylama create_directory 应该不需要手动创建文件夹。
  • @galiylama from_connection_string 是创建指向数据湖的链接。接下来的两个步骤是定义文件系统和文件夹以及 blobname。
猜你喜欢
  • 2011-06-21
  • 2021-06-10
  • 2017-12-14
  • 2019-04-03
  • 1970-01-01
  • 2021-07-09
  • 2017-04-17
  • 2012-03-02
  • 2016-03-04
相关资源
最近更新 更多