当前位置: 移动技术网 > IT编程>脚本编程>Python > python访问hdfs的操作

python访问hdfs的操作

2020年06月14日  | 移动技术网IT编程  | 我要评论

姜雨蒙,麻生希吧,好色女子高生

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"

以上这篇python访问hdfs的操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网