Azure blob 错误 :The specified blob does not exist, 但 Blob 存在

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

运行我的 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

screen shot

<小时/>

 datalake is blob

最佳答案

enter image description here

示例代码(请确保“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())

关于Azure blob 错误 :The specified blob does not exist, 但 Blob 存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66812662/

相关文章:

sql - 使用标识而不是顺序时的随机数

c# - 如何使用 .NET 存储 SDK 列出 Azure 文件存储中根目录中的所有目录或文件?

c# - 尝试 Azure 与 Unity 连接时获取 "NotImplementedException"(c#)

Azure Synapse Pipeline如何将每个文件作为sql脚本执行?

azure - 大众交通消费者没有接到电话

ios - Azure 电子邮件登录注册 b2c iOS swift

Azure 流分析 : identify right sizing and best practice to optimize ingestion to DataLaand processing

python - 从 ADLS2 传输到计算目标的速度非常慢 Azure 机器学习

azure - 检查 Azure blob 容器中是否存在项目需要很长时间(SDK 2.0)

amazon-web-services - azure 中是否可以进行跨租户 blob 访问?