InterLinked
InterLinked

Reputation: 1403

invalid level choice: choose from parser.log_levels

I am trying to make use of an open source Python program. I have a Python script configured exactly as per an example with all the pre-reqs installed, but I seem to be getting some kind of global Python error:

Traceback (most recent call last):
  File "/etc/asterisk/scripts/detect/gong/gonglearn.py", line 15, in <module>
    from pyAudioAnalysis.audioTrainTest import extract_features_and_train
  File "/root/pyAudioAnalysis/pyAudioAnalysis/audioTrainTest.py", line 9, in <module>
    from pyAudioAnalysis import MidTermFeatures as aF
  File "/root/pyAudioAnalysis/pyAudioAnalysis/MidTermFeatures.py", line 8, in <module>
    from pyAudioAnalysis import audioBasicIO
  File "/root/pyAudioAnalysis/pyAudioAnalysis/audioBasicIO.py", line 6, in <module>
    import eyed3
  File "/usr/local/lib/python2.7/dist-packages/eyed3/__init__.py", line 31, in <module>
    from .utils.log import log                                          # noqa: E402
  File "/usr/local/lib/python2.7/dist-packages/eyed3/utils/__init__.py", line 361
    msg = f"invalid level choice: {level} (choose from {parser.log_levels})"


SyntaxError: invalid syntax

I went to look at the code for __init__.py and I found:

 def __call__(self, parser, namespace, values, option_string=None):
        values = values.split(':')
        level, logger = values if len(values) > 1 else (values[0],
                                                        self.main_logger)

        logger = logging.getLogger(logger)
        try:
            logger.setLevel(logging._nameToLevel[level.upper()])
        except KeyError:
            msg = f"invalid level choice: {level} (choose from {parser.log_levels})"
            raise argparse.ArgumentError(self, msg)

        super(LoggingAction, self).__call__(parser, namespace, values, option_string)

Since this appears to be system code, or something with eyed3, not specific to what I am trying to run, I am not really sure how to proceed. I can't find any references anywhere on how to debug this particular error.

What problem exactly is this indicating? I'm usually able to resolve syntax errors myself, but in this case the message seems a bit cryptic and I can't decipher it. I tried importing various other things into my script and doing import logging as log but neither of those has helped any. Do I have to somehow configure logging in Python before I can use it?

I apologize if this is a weird issue, but it seems fairly obscure, and it's been a while since I've used Python before, and that was on Windows.

I am running Python (not Python 3) on Debian 10.

Upvotes: 1

Views: 178

Answers (1)

tim-mccurrach
tim-mccurrach

Reputation: 6835

The problem here is with the line suggested in the traceback:

msg = f"invalid level choice: {level} (choose from {parser.log_levels})"

The issue here is that this line is using f-strings, to do string interpolation. The reason this is a problem is that f-strings weren't introduced until python 3.6.

Unfortunately, because this is code from eyed3 you can't change it. You do have a few options though:

  • Upgrade your version of python to at least 3.6 (probably the best option)
  • fork the library, and edit that line so that you can use it with your version of python. Install your forked version. (This is probably a bad idea, this is unlikely to be the only place where there are incompatibilities. You will likely have to update quite a lot. It'll be easier to just update the version of python you're using).

If you look at the getting started section of the eyeD3 repo, it says:

Python >= 3.6 is required.

Upvotes: 1

Related Questions