Jihjohn
Jihjohn

Reputation: 438

Creating new files on heroku while app is working?

I have a python telegram bot and I have deployed it on Heroku. But problem is that my program actually creates pickled files while working. I have one database which is saving the required data and pickles to save some nested classes which I have to use later at some stage. So these pickle files are one of the important parts of the program. I am using the dill module for pickling. I was able to save these files locally, but can't do when I am doing it in Heroku. I'll share the logs below. It is not even reaching the pickling part, but giving an error in opening the file itself.

import dill


def saving_test(test_path, test_obj):
    try:
        save_test_logger.info('Saving test...')
        try:
            save_test_logger.info('opening file')
            test_file = open(test_path, 'wb')
        except Exception as exc:
            save_test_logger.exception('Error opening file')
            return 0

        dill.dump(test_obj, test_file)
        save_test_logger.debug(f'file saved in {test_path}')
        test_file.close()
        return 1
    except Exception as exc:
        save_test_logger.exception('saving error')
        test_file.close()
        return exc
saving 859ab1303bcd4a65805e364a989ac8ca
2020-10-07T20:53:18.064670+00:00 app[web.1]: Could not open file ./test_objs/859ab1303bcd4a65805e364a989ac8ca.pkl

And I have added logging also to my program, but now I am confused about where can I see the original logs which are supposed to catch the exceptions also. This is my first time using Heroku and I am comparatively new to programming also. So please help me out here to identify the route cause of the problem.

Upvotes: 0

Views: 549

Answers (1)

Jihjohn
Jihjohn

Reputation: 438

I found the problem. Even though I have pushed everything, directory test_objs wasn't there on Heroku. I just added 2 more lines of code to make a directory using os module if the directory does not exist. That solved the problem. I am not deleting the question so that just in case someone gets stuck or confused in a similar kind of situation, this question might be able to help them.

Upvotes: 1

Related Questions