ERROR accessing file created by my program

Unable to access file I create locally.

Context: My Flask app fetches data and stores it in "data" folder. Corresponding Python code:

    data_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data')
    os.makedirs(data_dir, exist_ok=True)
    print (f"data_dir is {data_dir}")
    
    # Save the DataFrame to a CSV file in the 'data' directory
    output_file = os.path.join(data_dir, f'stock_data_{ticker}.csv')
    stock_data.to_csv(output_file)

I see Render is storing it at /opt/render/project/src/data/XYZ.csv

BUT it gives following error when trying to read from it

“Error: File data\stock_data_VTEB.csv not found.”. Corresponding Pythong code-

ticker_filename = f’data\stock_data_{ticker}.csv’
data = pd.read_csv(ticker_filename )

Hey,

Did you make sure to check your file path relative to the root of your project versus an absolute path? Also, backslashes are usually associated with Windows, so I’m not sure why the error is showing backslashes.

You mentioned ‘Unable to access file I created locally.’ Are these files uploaded to your GitHub repo (which isn’t recommended, by the way) so they’re deployed with your code on the filesystem? Or are you creating them at runtime? If it’s the latter, have you checked the filesystem via ‘Shell’ or SSH to see if the files are in the expected location?

Jérémy.
Render Support, UTC+3

1 Like

Also, backslashes are usually associated with Windows

Had to replace "" with os.join as I developed app in Windows. Thank you so much!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.