AttributeError:'tuple'对象没有属性'read' [英] AttributeError: 'tuple' object has no attribute 'read'

查看:2146
本文介绍了AttributeError:'tuple'对象没有属性'read'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码的行:

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()

其中'selected_pa​​th'是要下载文件的路径,'current_working'是要保存文件的路径。
当我运行脚本时,我检索这个错误:

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'对象没有属性'read' / p>

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

我要下载的文件是一个GPG隐藏文件,但我不认为这是事情。
对不起我的坏英语。

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.

推荐答案

功能 get_file_and_metadata 返回元组:文件和元数据。

Function get_file_and_metadata returns tuple: file and metadata.

从这里: https://www.dropbox.com/developers/core/start/python


除了文件之外,该方法还在其当前版本中返回文件的元数据
。每次对文件进行更改时,文件元数据的
rev字段也会更改。通过在您下载文件时保存
修订版,您将能够判断该
文件是否已被其他计算机或设备更新,并选择
下载该文件的较新版本

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.

将您的电话更改为 self.client.get_file_and_metadata 像这样: / p>

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

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

或只需使用 get_file ,如果您不需要元数据:

or just use get_file if you dont need the metadata:

download = self.client.get_file(selected_path)

这篇关于AttributeError:'tuple'对象没有属性'read'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆