import magic filename = '/home/jovyan/pi-ml/data/images/'+'W074FLEB9138.tiff' # Open the file in binary mode with open(filename, 'rb') as f: # Create a magic object magic_obj = magic.Magic() # Use magic to identify the file type file_type = magic_obj.from_buffer(f.read()) print(file_type)