FileNotFoundError thrown due to file name in file, rather than file itself

Liste des GroupesRevenir à cl python 
Sujet : FileNotFoundError thrown due to file name in file, rather than file itself
De : loris.bennett (at) *nospam* fu-berlin.de (Loris Bennett)
Groupes : comp.lang.python
Date : 11. Nov 2024, 15:05:56
Autres entêtes
Organisation : FUB-IT, Freie Universität Berlin
Message-ID : <87v7wt986z.fsf@zedat.fu-berlin.de>
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Hi,

I have the following in my program:

    try:
        logging.config.fileConfig(args.config_file)
        config = configparser.ConfigParser()
        config.read(args.config_file)
        if args.verbose:
            print(f"Configuration file: {args.config_file}")
    except FileNotFoundError:
        print(f"Error: configuration file {args.config_file} not found.  Exiting.")
        sys.exit(0)

and when I ran the program I got the error

  Error: configuration file /usr/local/etc/sc_mailer not found.  Exiting.

However, this file *does* exist and *can* be read.  By checking the
'filename' attribute of the exception I discovered that the problem was
the log file defined *in* the config file, namely

  [handler_fileHandler]
  class=FileHandler
  level=DEBUG
  formatter=defaultFormatter
  args=('/var/log/my_prog.log', 'a')

This log file did not exist.  The exception is thrown by

  logging.config.fileConfig(args.config_file)

My questions are:

1. Should I be surprised by this behaviour?
2. In terms of generating a helpful error message, how should one
   distinguish between the config file not existing and the log file not
   existing?

Cheers,

Loris

--
This signature is currently under constuction.

Date Sujet#  Auteur
11 Nov 24 * FileNotFoundError thrown due to file name in file, rather than file itself25Loris Bennett
11 Nov 24 +* Re: FileNotFoundError thrown due to file name in file, rather than file itself17Left Right
12 Nov 24 i`* Re: FileNotFoundError thrown due to file name in file, rather than file itself16Loris Bennett
12 Nov 24 i +* Re: FileNotFoundError thrown due to file name in file, rather than file itself3Left Right
13 Nov 24 i i`* Re: FileNotFoundError thrown due to file name in file, rather than file itself2Greg Ewing
13 Nov 24 i i `- Re: FileNotFoundError thrown due to (Posting On Python-List Prohibited)1Lawrence D'Oliveiro
12 Nov 24 i +- Re: FileNotFoundError thrown due to file name in file, rather than file itself1Mats Wichmann
12 Nov 24 i +- Re: FileNotFoundError thrown due to file name in file, rather than file itself1Chris Angelico
13 Nov 24 i +* Re: FileNotFoundError thrown due to file name in file, rather than file itself2Loris Bennett
14 Nov 24 i i`- Re: FileNotFoundError thrown due to file name in file, rather than file itself1Barry
13 Nov 24 i +- Re: FileNotFoundError thrown due to file name in file, rather than file itself1Roel Schroeven
14 Nov 24 i +- Re: FileNotFoundError thrown due to file name in file, rather than file itself1Michael Torrie
14 Nov 24 i +- Re: FileNotFoundError thrown due to file name in file, rather than file itself1Left Right
14 Nov 24 i +- Re: FileNotFoundError thrown due to file name in file, rather than file itself1Chris Angelico
13 Nov 24 i +- Re: FileNotFoundError thrown due to file name in file, rather than file itself1D'Arcy Cain
14 Nov 24 i +- Re: FileNotFoundError thrown due to file name in file, rather than file itself1Ethan Furman
14 Nov 24 i `* Re: FileNotFoundError thrown due to file name in file, rather than file itself2Michael Torrie
14 Nov 24 i  `- Re: FileNotFoundError thrown due to file name in file, rather than file itself1Jon Ribbens
11 Nov 24 +- Re: FileNotFoundError thrown due to file name in file, rather than file itself1dieter.maurer
11 Nov 24 +- Re: FileNotFoundError thrown due to (Posting On Python-List Prohibited)1Lawrence D'Oliveiro
12 Nov 24 `* Re: FileNotFoundError thrown due to file name in file, rather than file itself5Chris Angelico
12 Nov 24  +* Re: FileNotFoundError thrown due to file name in file, rather than file itself3Loris Bennett
13 Nov 24  i+- Re: FileNotFoundError thrown due to file name in file, rather than file itself1dieter.maurer
14 Nov 24  i`- Re: FileNotFoundError thrown due to file name in file, rather than file itself1Kushal Kumaran
12 Nov 24  `- Re: FileNotFoundError thrown due to file name in file, rather than file itself1Loris Bennett

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal