Dear JAZZ 大大
以附上程式碼與錯誤訊息,麻煩您指點指點了!
然後想把windows底下的檔案傳到有虛擬ip的vm machine(ubuntu)裡的HDFS
不知道可不可行。
程式碼代碼:
from webhdfs import WebHDFS
import os, tempfile
import time
webhdfs = WebHDFS("192.168.88.67", 50070, "hdp2")
webhdfs.mkdir("/hello-world/")
# create a temporary file
f = tempfile.NamedTemporaryFile()
f.write(b'Hello world!\n')
f.flush()
print "Upload file: " + f.name
webhdfs.copyFromLocal(f.name,
"/hello-world/test1.txt")
webhdfs.copyToLocal("C:\\Users\\pyng\\Desktop\\test.txt",
"/hello-world/test1.txt")
for i in webhdfs.listdir("/hello-world/"):
print str(i)
f.close()
錯誤訊息代碼:
09/13/2013 05:02:42 PM - webhdfs - DEBUG - Create directory: /webhdfs/v1/hello-world/?op=MKDIRS&user.name=hdp2
09/13/2013 05:02:42 PM - webhdfs - DEBUG - HTTP Response: 200, OK
Upload file: c:\users\pyng\appdata\local\temp\tmpjavu0w
09/13/2013 05:02:42 PM - webhdfs - DEBUG - HTTP Response: 307, TEMPORARY_REDIRECT
09/13/2013 05:02:42 PM - webhdfs - DEBUG - HTTP Location: http://hdp2:50075/webhdfs/v1//hello-world/test1.txt?op=CREATE&user.name=hdp2&overwrite=true
09/13/2013 05:02:42 PM - webhdfs - DEBUG - Send redirect to: host: hdp2, port: 50075, path: /webhdfs/v1//hello-world/test1.txt?op=CREATE&user.name=hdp2&overwrite=true&replication=1
Traceback (most recent call last):
File "C:\Users\pyng\workspace\pythone_hdfs_test\webhdfs-py-master\webhdfs\example.py", line 17, in <module>
"/hello-world/test1.txt")
File "C:\Users\pyng\workspace\pythone_hdfs_test\webhdfs-py-master\webhdfs\webhdfs.py", line 74, in copyFromLocal
fileUploadClient.request('PUT', redirect_path, open(source_path, "r").read(), headers={})
IOError: [Errno 13] Permission denied: 'c:\\users\\pyng\\appdata\\local\\temp\\tmpjavu0w'