2014-02-11 60 views
0

我試圖通過一系列包含excel工作簿的保存箱中的文件夾。 我目前正在嘗試使用dropbox api來查找該文件並將其作爲輸入文件下載到本地文件夾中,以便我可以解析單元格以獲取特定信息,然後刪除臨時輸入文件到Dropbox中的下一個文件夾以獲取下一個輸入文件。Dropbox API錯誤「具有該名稱的文件已存在於路徑中」

程序的第一個輸入文件失敗,一個錯誤,指出:

ErrorResponse: [403] u"A file with that name already exists at path 

但沒有任何文件的文件夾時,我去檢查一下。

conn = dropbox.client.DropboxClient(sess) 
folder_metadata = conn.metadata("/Apps/Attachments") #Base folder where folders with input files are located 

#Go through each folder 
for item in folder_metadata["contents"]: 
    temp_path = item["path"] 
    print temp_path 

    #Download file called '2014.xlsx' and save it in a local folder as 'input.xlsx' 
    conn.file_copy(temp_path + "/2014.xlsx", "/Users/myusername/Desktop/DropboxAPI/input.xlsx") 

    #Code that parses through input.xlsx 

    os.remove("input.xlsx") 

任何人有類似的問題嗎?我正在Mac OS X上編程(10.9.1)

回答

0

您打電話給file_copy,它將Dropbox中的文件複製到不同的位置(在Dropbox中)。我想你想要的是將文件下載到本地計算機。爲此,您應該使用get_file

事情是這樣的:

with file('/Users/myusername/Desktop/DropboxAPI/input.xlsx', 'wb') as fout: 
    with conn.get_file(temp_path) as fin: 
     fout.write(fin.read()) 
相關問題