imghdr.whataccepts an optional second argument. If specified, the first argument is ignored and the second argument is assumed to contain image bytes.
So you can change the following line:
print imghdr.what(image_file.getvalue())
from:
print imghdr.what(None, image_file.getvalue())
source
share