简体   繁体   English

使用 Python(无 ADB)读取 Azure ADLS Gen2 文件

[英]Azure ADLS Gen2 File read using Python (without ADB)

Want to read files(csv or json) from ADLS gen2 Azure storage using python(without ADB) .想要使用 python(without ADB) 从 ADLS gen2 Azure 存储中读取文件(csv 或 json)。

file  = DataLakeFileClient.from_connection_string(conn_str=conn_string,file_system_name="test", file_path="source")

with open("./test.csv", "r") as my_file:
    file_data = file.read_file(stream=my_file)

Error : Exception has occurred: AttributeError 'DataLakeFileClient' object has no attribute 'read_file'错误:发生异常:AttributeError 'DataLakeFileClient' 对象没有属性 'read_file'

My try is to read csv files from ADLS gen2 and convert them into json.我的尝试是从 ADLS gen2 读取 csv 文件并将它们转换为 json。 Download.readall() is also throwing the ValueError: This pipeline didn't have the RawDeserializer policy; Download.readall() 也抛出 ValueError: This pipeline didn't have the RawDeserializer policy; can't deserialize.无法反序列化。

Try the below piece of code and see if it resolves the error:试试下面的代码,看看它是否能解决错误:

import os, uuid, sys
from azure.storage.filedatalake import DataLakeServiceClient

service_client = DataLakeServiceClient.from_connection_string("DefaultEndpointsProtocol=https;AccountName=***;AccountKey=*****;EndpointSuffix=core.windows.net")

file_system_client = service_client.get_file_system_client(file_system="test")

directory_client = file_system_client.get_directory_client("testdirectory")

file_client = directory_client.get_file_client("test.txt")

download=file_client.download_file()

downloaded_bytes = download.readall()

with open("./sample.txt", "wb") as my_file:
    my_file.write(downloaded_bytes)
    my_file.close()

Also, please refer to this Use Python to manage directories and files MSFT doc for more information.此外,请参阅此使用 Python 管理目录和文件MSFT 文档以获取更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Python 将文件上传到 ADLS Gen2 - How to upload a file to ADLS Gen2 using Python 使用 Azure CLI、Rest API 或 Python 在 Azure ADLS gen2 中复制文件 - Copy files within Azure ADLS gen2 using Azure CLI, Rest API or Python 使用Python或Java从本地将数据上传到Azure ADLS Gen2 - Upload data to the Azure ADLS Gen2 from on-premise using Python or Java 如何通过读取存储在 Databrciks 中的 adls gen2 中的 csv 文件(特定列)来创建 ADLS gen2 中的文件夹 - how to ceate folders in ADLS gen2 by reading a csv file(particular column) stored in adls gen2 in Databrciks 如何将URL中的图片保存到azure中的blob存储ADLS gen2 in python - how to save the picture in a URL into azure blob storage ADLS gen2 in python 通过数据块从 ADLS gen2 存储中的多个文件夹中读取文件并创建单个目标文件 - Read files from multiple folders from ADLS gen2 storage via databricks and create single target file 如何使用 Azure Synapse 和 pySpark 笔记本从 ADLS gen2 检索 .dcm 图像文件? - How to retrieve .dcm image files from the ADLS gen2 using Azure Synapse and pySpark notebook? Azure Data Lake Storage Gen2 (ADLS Gen2) 作为 Kedro 管道的数据源 - Azure Data Lake Storage Gen2 (ADLS Gen2) as a data source for Kedro pipeline 如何使用 pandas 读取存储在 adls gen 2 中的文件? - How to read a file stored in adls gen 2 using pandas? Azure Databricks pyspark readstream 从挂载的ADLS Gen2输入路径读取非orc文件 - Azure Databricks pyspark readstream reads non orc files from the mounted ADLS Gen2 input path
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM