Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot understand error when decoding base 64 encoded graphic

I imported a file background_image.txt containing the string reference background_image a base 64 encoded graphic. When I compile the program I get the error in the error log:

Traceback (most recent call last):
  File "main.py", line 23, in <module>
    background_image = io.StringIO(base64.decode(background_image.background_image))
TypeError: decode() missing 1 required positional argument: 'output'

This is line #23

background_image = io.StringIO(base64.decode(background_image.background_image)) # line 23

This is the reduced verison of my program. This program creates a window using tkinter using the base 64 encoded graphic as the canvas background.

# modules
from tkinter import *
from PIL import ImageTk, Image
import io
import base64

# imported files
import background_image 

# variables 
background_image = io.StringIO(base64.decode(background_image.background_image)) # line 23

# window creation
root = Tk()

# canvas creation
canvas = Canvas(root, width=600, height=600, bd=-2) 
canvas.pack()

# canvas attributes 
background = ImageTk.PhotoImage(file=background_image)
canvas.create_image(0, 0, image=background, anchor=NW)
text = canvas.create_text(125, 75, anchor=CENTER)

# end
root.after(0, display)
root.mainloop()
like image 270
user4261180 Avatar asked Sep 17 '25 12:09

user4261180


1 Answers

According to the documentation, base64.decode takes 2 arguments: input and output.

You certainly want to use base64.b64decode(s) which returns the decoded string.

like image 76
tcollart Avatar answered Sep 20 '25 02:09

tcollart