def get_image_as_base64(filename): with open(filename, 'rb') as fp: content = fp.read() return base64.b64encode(content).decode('ascii')