【问题标题】:IOError: [Errno 2] No such file or directory: 'hdfs:///data/testdata.json'IOError:[Errno 2] 没有这样的文件或目录:'hdfs:///data/testdata.json'
【发布时间】:2018-08-07 14:05:56
【问题描述】:

python 编码新手,遇到以下错误

我可以查看该位置使用的 testdata.json'

hdfs dfs -ls /data/testdata.json'

Traceback(最近一次调用最后一次): 文件“testdata.json”,第 6 行,在 使用 open('hdfs:///data/testdata.json') 作为数据文件: IOError:[Errno 2] 没有这样的文件或目录:'hdfs:///data/testdata.json' python process_sensor_file.py

#!/bin/python
import json
from pprint import pprint

with open('hdfs:///data/testdata.json', "r") as data_file:
     source_data = json.load(data_file)
print(source_data)

print(json.dumps(source_data, indent=2))

for item in source_data['CityData']:
            Longitude = item['Longitude']
            TimeStamp = item['TimeStamp']
            print(Longitude, TimeStamp)

【问题讨论】:

  • 阅读此链接,可能会有所帮助stackoverflow.com/questions/42447912/…
  • 我在打开 json 文件的语句时遇到问题。文件“testdata.json”,第 6 行,使用 open('hdfs:///data/testdata.json') as data_file: IOError: [Errno 2] No such file or directory

标签: python


【解决方案1】:

您需要一个用于 python 的 HDFS 驱动程序才能从 HDFS 读取,例如 hdfs3

来自docs

from hdfs3 import HDFileSystem
hdfs = HDFileSystem(host='localhost', port=8020)
with hdfs.open('/data/testdata.json') as f:
    data = f.read(1000000)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多