def _remove_exif_tag(self, pil_img: TextIO) -> TextIO: exif = pil_img.getexif() # Remove all exif tags for k in exif.keys(): if k != 0x0112: exif[ k] = None # If I don't set it to None first (or print it) the del fails for some reason. del exif[k] # Put the new exif object in the original image new_exif = exif.tobytes() pil_img.info["exif"] = new_exif return pil_img