Permission denied - Logging

Asked

Viewed 311 times

1

I implemented the Logging python on several Flask projects successfully. But when I tried to re-implement Logging in a project it gives the following error:IOError: [Errno 13] Permission denied.

To try to solve the problem I created the file and still the error continues. Strange this error occurs after having used the same code for all previous projects.

Supposedly the error occurs in the following code:

if __name__ == '__main__':
    import logging
    logging.basicConfig(filename='error.log', level=logging.WARNING)
    app.run()
  • which user is running the application?

  • Tries to change the file location.

  • This is running on my development machine. So it should have all the permissions.

1 answer

0


This mistake, number 13, is related to permissions. The process that is running your website is not authorized to create or modify the file error log. in the tried directory.

As your example is from Flask and runs app.run() I can assume that the user is yourself, as this is the development webserver embedded in Flask.

So in this case, most likely you are running your script from a development directory, created by you, with all the necessary permissions. The only conclusion I have left is that the file error log. is not being created within this directory.

A simple attempt to make your code work is to be more explicit about the location of the file by passing the full path.

Example, assuming you wish error log. in the same directory as the script:

  • The funny thing is that the file is inside the Flask project, as I did in all the other previous projects.

  • put a print os.getcwd() shortly after the import logging to confirm what the current directory is and if it really is what you are thinking. I often prefer to use absolute paths to the file, thus avoiding these kind of surprises.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.