Closed kristiankiralyfp closed 5 years ago
@thebigmunch if it helps, I can send the song that raises the exception in case it's specific to this file, but it's too large to fit in an attachment to this comment (26.4 MB)
The below prints "Test" and then crashes with the exception:
The snippet doesn't seem to show the traceback of the exception, so doesn't do much to help : P
I can send the song that raises the exception in case it's specific to this file, but it's too large to fit in an attachment to this comment (26.4 MB)
Sure, that'd be great, too.
Also, I have the exceptions at the top level of the module, so you can do: except audio_metadata.InvalidHeader
to save some typing unless you are being super explicit.
Thanks for the tip on syntactic sugar! I'll keep that in mind.
As for the traceback:
Traceback (most recent call last):
File "test.py", line 28, in <module>
metadata = audio_metadata.load(f)
File "/usr/local/lib/python3.7/site-packages/audio_metadata/api.py", line 119, in load
return parser_cls.load(fileobj)
File "/usr/local/lib/python3.7/site-packages/audio_metadata/formats/wav.py", line 91, in load
raise InvalidHeader("Valid WAVE header not found.")
audio_metadata.exceptions.InvalidHeader: Valid WAVE header not found.
Here's a link to the song: https://we.tl/t-eIeI77TWXg
Though the exception is not the issue, I expect it to cause an exception. I just want to be able to catch it and continue execution!
Yeah, you're looking for some basic Python syntax. You should be doing the <metadata processing>
bit in an else clause to your try. That way it only runs if the try part of it doesn't throw an exception.
More info can be found in the Python exceptions docs.
Good luck.
Right you are! Thanks for the help :)
I find that when I try to catch InvalidHeader exceptions on audio_metadata.load() the code will not execute in the 'except audio_metadata.exceptions.InvalidHeader:' block. Even a 'print("test")' does not execute if I catch the exception. My only options are to not catch the exception and have the code crash or to catch it and then raise it again to have the code crash.
I have a loop that iterates over a list of files to grab metadata from each. The first step is trying to get the metadata, and I handle exceptions right away before the rest of the loop code is executed.
The below prints "Test" and then crashes with the exception:
The below does not print "Test" and hangs:
In case it helps, this is the way my loop is set up:
Sorry, I'm pretty new to adding issues to GitHub and can't figure out how to show indentation, but it is all properly indented in code.
Thank you, thebigmunch, for fixing my formatting!