How to check if a file is a valid image file?

I have just found the builtin imghdr module. From python documentation: The imghdr module determines the type of image contained in a file or byte stream. This is how it works: >>> import imghdr >>> imghdr.what(‘/tmp/bass’) ‘gif’ Using a module is much better than reimplementing similar functionality UPDATE: imghdr is deprecated as of python 3.11

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)