【发布时间】:2022-02-09 17:40:45
【问题描述】:
我正在尝试将 s3 文件夹文件下载到我的 windows 系统中,但在 windows 系统中执行我的 python 脚本时出现权限错误。 任何帮助将不胜感激。
# creating folder but no data.
import boto3
import os
from pathlib import Path
s3 = boto3.resource('s3')
bucket = s3.Bucket('mybucketname')
key = 'foldername1'
objs = list(bucket.objects.filter(Prefix=key))
for obj in objs:
# print(obj.key)
# remove the file name from the object key
obj_path = os.path.dirname(obj.key)
# create nested directory structure
Path(obj_path).mkdir(parents=True, exist_ok=True)
# save file with full path locally
bucket.download_file(obj.key, obj.key)
我得到以下错误:
Traceback (most recent call last):
File "C:\MSA\EO projects\FEB 2022 WORKS\REMOTE AWZ\d6.py", line 23, in <module>
bucket.download_file(obj.key, obj.key)
File "C:\Program Files\Python37\lib\site-packages\boto3\s3\inject.py", line 246, in bucket_download_file
ExtraArgs=ExtraArgs, Callback=Callback, Config=Config)
File "C:\Program Files\Python37\lib\site-packages\boto3\s3\inject.py", line 172, in download_file
extra_args=ExtraArgs, callback=Callback)
File "C:\Program Files\Python37\lib\site-packages\boto3\s3\transfer.py", line 307, in download_file
future.result()
File "C:\Program Files\Python37\lib\site-packages\s3transfer\futures.py", line 106, in result
return self._coordinator.result()
File "C:\Program Files\Python37\lib\site-packages\s3transfer\futures.py", line 265, in result
raise self._exception
File "C:\Program Files\Python37\lib\site-packages\s3transfer\tasks.py", line 126, in __call__
return self._execute_main(kwargs)
File "C:\Program Files\Python37\lib\site-packages\s3transfer\tasks.py", line 150, in _execute_main
return_value = self._main(**kwargs)
File "C:\Program Files\Python37\lib\site-packages\s3transfer\download.py", line 601, in _main
osutil.rename_file(fileobj.name, final_filename)
File "C:\Program Files\Python37\lib\site-packages\s3transfer\utils.py", line 273, in rename_file
rename_file(current_filename, new_filename)
File "C:\Program Files\Python37\lib\site-packages\s3transfer\compat.py", line 25, in rename_file
os.remove(new_filename)
PermissionError: [WinError 5] Access is denied: 'foldername1/'
【问题讨论】:
标签: python amazon-web-services amazon-s3 download boto3