Reputation: 447
From what I understand on temp file's and directories, the following code should be ok, but I'm getting a permission denied error message.
What I'm trying to do here is download a s3 file and write the contents to another file inside the TemporaryDirectory
s3_client = boto3.client('s3')
with tempfile.TemporaryDirectory(prefix='some_prefix') as temp_dir:
with open('some_name.csv', 'w+b') as f:
s3_client.download_fileobj(bucket.name, file_path, f)
f.seek(0)
Output:
PermissionError: [Errno 13] Permission denied: 'some_name.csv'
Upvotes: 0
Views: 979
Reputation: 169051
You're not using temp_dir
at all, and as such 'some_name.csv'
refers to your process's working directory. Use e.g. os.path.join
:
with open(os.path.join(temp_dir, 'some_name.csv'), 'w+b') as f:
Upvotes: 2