I try to upload a zip file to my S3 bucket, but getting
^{pr2}$AttributeError: 'ZipFile' object has no attribute 'tell' error
这里怎么了?(zipf是我的zipfile)
如果我像这样修改代码
with open(zipf) as f:
k.send_file(f)
我明白了
TypeError: coercing to Unicode: need string or buffer, ZipFile found
我创建的zip文件如下
zipfilename = 'AAA_' + str(datetime.datetime.utcnow().replace(microsecond=0)) + '.zip'
zipf = zipfile.ZipFile(zipfilename, mode='w')
for root, dirs, files in os.walk(path):
for f in files:
zipf.write(os.path.join(root, f))
zipf.close()
您的zipfile是用
zipf = zipfile.ZipFile(zipfilename, mode='w')
创建的。在在zipfile documentation之后,
tell()
属性只为mode='r'
定义。在没有理由使用zipfile对象,而且在写模式下,上载我们想要读取的文件(无论是zip文件还是其他文件),以便将其上载到S3。在
只需在调用键上的
open(zipfilename, 'r')
之前使用open(zipfilename, 'r')
。在相关问题 更多 >
编程相关推荐