Invalid base64-encoded string: number of data characters (13) cannot be 1 more than a multiple of 4

6.6k Views Asked by At

I just started coding with Python , I have an image that is supposed to be decoded by the base64 module as I understood , but I keep getting this error :" Invalid base64-encoded string: number of data characters (13) cannot be 1 more than a multiple of 4 " , I changed the syntax of the code so I started getting an error of padding instead.

def call_dalle(url, text, num_images=1):
    data = {"text": text, "num_images": num_images}
    resp = requests.post(url + "/dalle", headers=headers, json=data)
    if resp.status_code == 200:
        return resp
    
def create_and_show_images(text, num_images):
    valid = check_if_valid_backend(URL)
    if not valid:
        st.write("Backend service is not running")
    else:
        resp = call_dalle(URL, text, num_images)
        if resp is not None:
            for data in resp.json():
                img_data = base64.b64decode(data + "=" * 3)
                st.image(img_data)

I tried most of the solutions that I found to similar problems but nothing worked so far.

0

There are 0 best solutions below