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!

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.

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'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.