如何使用Python进行HDFS文件访问操作?
- 内容介绍
- 文章标签
- 相关推荐
本文共计229个文字,预计阅读时间需要1分钟。
使用pip安装hdfs-python库,读取HDFS目录或文件:
pythonpip install hdfs-pythonimport hdfs.clientclient=hdfs.Client(http://10.10.1.4:50070)fileDir=/user/hive/warehouse/house.db/dm_house/dt=201800909status=client.status(fileDir, False)if status: print(status)
pip install hdfs
python 读取hdfs目录或文件
import hdfs client =hdfs.Client("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 "Hadoop:50070/webhdfs/v1/?user.name=hadoop&op=LISTSTATUS"
以上这篇python访问hdfs的操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。
本文共计229个文字,预计阅读时间需要1分钟。
使用pip安装hdfs-python库,读取HDFS目录或文件:
pythonpip install hdfs-pythonimport hdfs.clientclient=hdfs.Client(http://10.10.1.4:50070)fileDir=/user/hive/warehouse/house.db/dm_house/dt=201800909status=client.status(fileDir, False)if status: print(status)
pip install hdfs
python 读取hdfs目录或文件
import hdfs client =hdfs.Client("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 "Hadoop:50070/webhdfs/v1/?user.name=hadoop&op=LISTSTATUS"
以上这篇python访问hdfs的操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

