[英]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.