Search code examples
pythonlinuxrelative-pathboto3

Relative path not working in Python


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


Solution

  • 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: