core-site.xml 配置信息
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:9000</value>
</property>
from hdfs.client import Client
client = Client("http://localhost:9000", root="/", timeout=100, session=False)
result = client.list("/")
print result
如果访问core的配置的信息是无法访问,会有以下报错
It looks like you are making an HTTP request to a Hadoop IPC port. This is not the correct port for the web interface on this daemon.
这里要使用的是web可访问的管理页面的地址
hadoop3的 NameNode管理页面
http://localhost:9870可
如果启动了hdfs可直接浏览器打开
代码改为
from hdfs.client import Client
client = Client("http://localhost:9870", root="/", timeout=100, session=False)
result = client.list("/")
print result
如果要使用rpc 9000的端口的话
from snakebite.client import Client
client = Client("localhost", 9000, use_trash=False)
result = list(client.ls(['/']))
print result