将图像文件编码为base64

Encode image file to base64

我无法将图像转换为 base64 并通过 xml-rpc 客户端发送,xml-RPC 服务器响应并给出此错误

a bytes-like object is required, not '_io.BufferedReader'

import base64
        with open(full_path, 'rb') as imgFile:
            image = base64.b64encode(imgFile)

您提供了文件指针,但应该提供二进制数据。

你应该这样写:

import base64
with open(full_path, 'rb') as imgFile:
    image = base64.b64encode(imgFile.read())