Forums

Flask App - issue with file paths

Hi - I am trying to get a Flask app to run, and my app code has some file paths to some files in the project directory structure which the app opens and parses.

quote_files = ['._data/DogQuotes/DogQuotesTXT.txt',
               '._data/DogQuotes/DogQuotesDOCX.docx',
               '._data/DogQuotes/DogQuotesPDF.pdf',
               '._data/DogQuotes/DogQuotesCSV.csv']

The flask app throws an error on loading saying it cannot find the directory or files (see below). I have a CLI interface to the same program which works just fine. Can anyone advise me on this?

FileNotFoundError: [Errno 2] No such file or directory: '._data/DogQuotes/DogQuotesTXT.txt'

See https://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/

Thanks Glenn. I had seen that resource and tried putting in the full absolute paths but same error. Is this something to do with the virtualenv perhaps?

any ideas?

What error do you get exactly when you use absolute paths?

when I use txt it only works when I dont add the .txt

You need to use the actual filename that your file is stored as. If you use a different filename, then it will not find it. Alternatively, if you're using some sort of library to load the files, perhaps the library has some code that make assumptions about file extensions and automatically adds it it some cases - check the documentation for the library to see if they say anything about that.

One thing that does stand out about your file paths is that they all seem to start with ._data. Is that directory called ._data? If it's not and it's perhaps called .data, then that may be the issue with your paths.