pip install hdfs
python 讀取hdfs目錄或文件
import hdfs client =hdfs.Client("http://10.10.1.4:50070") fileDir="/user/hive/warehouse/house.db/dm_house/dt=201800909" try: status=client.status(fileDir,False) if status: print (status) rst=client.download(fileDir,"/home/dev/gewei") print (rst) exception Exception as e: print (e)
補充知識:用python訪問hdfs出現webhdfs找不到的情況
有可能是webhdfs服務沒有開啟
向hdfs-site.xml文件中添加屬性:
dfs.webhdfs.enabledtrue
可以使用如下命令檢測,
獲得目錄的列表:
curl -i "http://Hadoop:50070/webhdfs/v1/?user.name=hadoop&op=LISTSTATUS"
[zmcjlove ] python訪問hdfs的操作已經有246次圍觀