Search code examples
pythonbase64odoonewlineencode

Python attachemnt.encode('base64') removes \n


I'm using Odoo and to upload a text file I need to encode it with base64, but encoding removes all '\n' elements and then I have everything in one line. How can I leave those new lines?

with open("Invoices.txt") as text_file:
                attachment=text_file.read()
                new_attach =attachment.encode('base64')

Solution

  • Just had to open file as 'rb' not 'r'