#type error: a bytes-like object is required, not 'str' occurs when trying to write a base64 string

8 messages · Page 1 of 1 (latest)

olive belfry
#

I am trying to write a base64 sstring to a file using the following method:

with open("./system/asset/key.bin", "wt") as f:
            f.write(base64.b64encode(choice))
            f.close()

However, this fails, and throws an error as shown in the image

lilac ice
#

You need to encode your string as bytes first

#

Something like base64.b64encode(choice.encode("ascii"))

#

@olive belfry

olive belfry
#

okay

#

i;; try in a bit