The error is not understood otherwise and user is forced to look inside code to find what is going on.
Instead this is the displayed error: "UnboundLocalError: local variable 'image' referenced before assignment" because none of the conditions in if-statements where true so 'image' variable wouldn't have been defined hence this error, which is misleading since the real error resides at the input that shouldn't make the 'read' operation fail: raise an Exception that clearly shows that.
The error is not understood otherwise and user is forced to look inside code to find what is going on. Instead this is the displayed error: "UnboundLocalError: local variable 'image' referenced before assignment" because none of the conditions in if-statements where true so 'image' variable wouldn't have been defined hence this error, which is misleading since the real error resides at the input that shouldn't make the 'read' operation fail: raise an Exception that clearly shows that.