python如何访问hdfs

python如何访问hdfs

这篇文章主要为大家展示了python如何访问hdfs,内容简而易懂,希望大家可以学习一下,学习完之后肯定会有收获的,下面让小编带大家一起来看看吧。

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/&#63;user.name=hadoop&op=LISTSTATUS"

以上就是关于python如何访问hdfs的内容,如果你们有学习到知识或者技能,可以把它分享出去让更多的人看到。