Python attachemnt.encode('base64') remove



我正在使用Odoo并上传文本文件,我需要使用base64对其进行编码,但是编码会删除所有""元素,然后我将所有内容都在一行中。我怎样才能离开这些新行?

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

只需要以"rb"而不是"r"打开文件

即可

最新更新