code: def read_exif_from_file(filename):
      
      f = open(filename, "rb")
      data = f.read(6)
  
      if data[0:2] != b"\xff\xd8":
          raise InvalidImageDataError("Given data isn't JPEG.")
  
      head = data[2:6]
      HEAD_LENGTH = 4
      exif = None
      while 1:
          length = struct.unpack(">H", head[2: 4])[0]
  
          if head[:2] == b"\xff\xe1":
              segment_data = f.read(length - 2)
              if segment_data[:4] != b'Exif':
                  head = f.read(HEAD_LENGTH)
                  continue
              exif = head + segment_data
              break
          elif head[0:1] == b"\xff":
              f.read(length - 2)
              head = f.read(HEAD_LENGTH)
          else:
              break
  
      f.close()
      return exif
docs: Slices JPEG meta data into a list from JPEG binary data.