我正在尝试使用boto代码从AWS S3下载.zip文件,但是会出现以下错误:
'str'对象没有属性'write'
代码
s3Conn = S3Connection(aws_access_key_id='ABCD',
aws_secret_access_key='xyz')
s3bucket = s3Conn.get_bucket(mybucket)
key = s3bucket.new_key("2015/02/20/TestFile.zip")
try:
key.get_contents_to_file(backupdir)
except:
print("{0}".format(sys.exc_info()))
答案 0 :(得分:2)
我认为backupdir
是字符串,但是boto期望文件对象(如open(backupdir)
)
答案 1 :(得分:0)
def downloadBackupFile(backupdir):
key = s3bucket.new_key("2015/02/20/TestFile.zip")
try:
if (os.path.exists(backupdir)):
key.get_contents_to_file(open(backupdir + "TestFile.zip", "w+"))
except:
print("{0}".format(sys.exc_info()))