我试图使用python脚本将文件从s3下载到我的Windows 10笔记本电脑。我正在运行 提示"作为管理员"。我已经让每个人都可以完全访问我尝试编写文件的文件夹 但是,Windows仍然会拒绝访问#34;错误。
import boto3
s3 = boto3.resource('s3')
s3.Bucket('kapps2.services-exchange.com').download_file('myconfig.py',
'C:\data')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\boto3\s3\inject.py", line 168, in
bucket_download_file
ExtraArgs=ExtraArgs, Callback=Callback, Config=Config)
File "C:\Python27\lib\site-packages\boto3\s3\inject.py", line 130, in
download_file
extra_args=ExtraArgs, callback=Callback)
File "C:\Python27\lib\site-packages\boto3\s3\transfer.py", line 307, in
download_file
future.result()
File "C:\Python27\lib\site-packages\s3transfer\futures.py", line 73, in
result
return self._coordinator.result()
File "C:\Python27\lib\site-packages\s3transfer\futures.py", line 233, in
result
raise self._exception
WindowsError: [Error 5] Access is denied: 'C:\\data'
我是Python的新手,任何人都可以帮忙吗?谢谢
答案 0 :(得分:1)
来自boto3文档(https://boto3.readthedocs.io/en/latest/guide/s3-example-download-file.html)
示例是: s3.Bucket(BUCKET_NAME).download_file(KEY,'my_local_image.jpg')
它指定目标文件名(my_local_image.jpg),而不仅仅是保存文件的目录。所以你的代码应该是:
s3.Bucket('kapps2.services-exchange.com').download_file('myconfig.py', 'C:/data/myconfig.py')