AttributeError: 'tuple' object has no attribute 'read'

泄露秘密 提交于 2019-12-12 01:05:28

问题


I have got this code's lines:

import dropbox

#some lines for initialize API's

download = self.client.get_file_and_metadata(selected_path)
current_working = os.getcwd()
out = open(current_working+self.filename,'w')
out.write(download.read())
out.close()

where 'selected_path' is the path where there is the file I want to download and 'current_working' is the path where I want to save the file. When I run the script, I retrieve this error:

AttributeError: 'tuple' object has no attribute 'read'

The file that I want to download is a GPG crypted file, but I don't think that is this the matter. Sorry for my bad english.


回答1:


Function get_file_and_metadata returns tuple: file and metadata.

from here: https://www.dropbox.com/developers/core/start/python

In addition to the file, the method also returns the file's metadata at its current revision. Every time a change is made to the file, the rev field of the file's metadata changes as well. By saving the revision when you download the file, you'll be able to tell if that file has been updated by another computer or device and choose to download the newer revision of that file.

change your call to self.client.get_file_and_metadata like this:

download, metadata = self.client.get_file_and_metadata(selected_path)

or just use get_file if you dont need the metadata:

download = self.client.get_file(selected_path)


来源:https://stackoverflow.com/questions/20734167/attributeerror-tuple-object-has-no-attribute-read

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!