Search code examples
python-3.6odooxml-rpc

Encode image file to base64


I have a trouble to convert an image to base64 and send it through xml-rpc client, the xml-RPC server respond and gives this error

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

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

Solution

  • You have given file pointer but should give binary data.

    You should write as following :

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