My Python script can't resolve the relative path on a Linux server in the following script:
import boto3
import os
conn = boto3.client('s3', region_name="eu-west-1", endpoint_url="https://example.com", config=Config(signature_version="s3", s3={'addressing_style': 'path'}))
conn.download_file('mytestbucket22', 'file.csv', os.path.join(os.getcwd(), 'static', 'filecache', 'file.csv'))
Error:
[Errno 2] No such file or directory: '/home/vcap/app/static/filecache/file.csv.D3e3D7aF'
However when I do it like this it works and it saves the file to the path of my script.
conn.download_file('mytestbucket22', 'file.csv', 'file.csv')
My folder and file structure looks like this:
--script.py
--static
----filecache
How can I save the file to the folder filecache? Thanks
conn.download_file('mytestbucket22', 'file.csv', os.path.join(os.getcwd(), 'static', 'filecache', 'file.csv'))
Documentation references for the modules, constants and functions used above:
os
and os.path
modules.__file__
constantos.path.realpath(path)
(returns "the canonical path of the specified filename, eliminating any symbolic links encountered in the path")os.path.dirname(path)
(returns "the directory name of pathname path
")os.getcwd()
(returns "a string representing the current working directory")os.chdir(path)
("change the current working directory to path
")