当前位置:主页 > 软件编程 > Python代码 >

python访问hdfs的操作

时间:2021-06-27 08:20:14 | 栏目:Python代码 | 点击:

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文件中添加属性:

<property> 
  <name>dfs.webhdfs.enabled</name> 
  <value>true</value> 
</property> 

可以使用如下命令检测,

获得目录的列表:

curl -i "http://Hadoop:50070/webhdfs/v1/?user.name=hadoop&op=LISTSTATUS"

您可能感兴趣的文章:

相关文章