kavise
kavise

Reputation: 215

python 2.7 access denined when writing a file to Windows

I'm trying to use a python script to download a file from s3 to my Windows 10 laptop. I'm running the prompt "as administrator". I have given everyone full access to the folder I'm trying to write the file to, but windows is still giving an "access denied" error.

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'

I'm new to Python, can anyone help with this? Thank You

Upvotes: 0

Views: 311

Answers (1)

Olivier Gaulard
Olivier Gaulard

Reputation: 76

From the boto3 documentation (https://boto3.readthedocs.io/en/latest/guide/s3-example-download-file.html)

The example is : s3.Bucket(BUCKET_NAME).download_file(KEY, 'my_local_image.jpg')

It is specifying the target filename (my_local_image.jpg) and not only the directory where to save the file. So your code should be :

s3.Bucket('kapps2.services-exchange.com').download_file('myconfig.py', 'C:/data/myconfig.py')

Upvotes: 2

Related Questions