0

Read title.

username = base64.b64encode(username)+'\n'

This is what I thought would have worked, but it comes up with an error, "TypeError: can't concat bytes to str", meaning that I cannot add +'\n' to the end of the code.

If there is anyway anyone knows how to write the byte of base64.b64encode(username) to a file line by line, please help!

3
Contributors
2
Replies
26
Views
3 Years
Discussion Span
Last Post by vegaseat
0

b64encode() return a bytes. Convert it to str with decode

result = base64.b64encode(username).decode('utf8')+'\n'

Notice that result has type str, while username is a bytes. I suggest not to use the same variable name in order to avoid type confusion.

0

Using Python3 you are dealing with byte strings.
So username has to be a byte string and '\n' has to be changed to b'\n'

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.