1
xlsxwriterを使用してxlsxファイルを生成し、それを電子メールの添付ファイルとして送信しようとしています。Django:バイトのようなオブジェクトを電子メールに添付できないようにするTypeError
def WriteToExcel(project):
output = BytesIO()
workbook = xlsxwriter.Workbook(output)
#putting in data
workbook.close()
xlsx_data = output.getvalue()
# xlsx_data contains the Excel file
return xlsx_data
def project_email (request, project_id):
project = Project.objects.get(id = project_id)
xlsx_data = WriteToExcel(project)
message = EmailMessage("Heading", 'Here is the message.', 'HOST', ['[email protected]'])
message.attach_file(xlsx_data)
message.send()
そして、私は電子メールを送信しようとしたとき、私は次のようなエラーがあります:ここで私は今持っているものである
TypeError at /projstatus/1/email
cannot use a string pattern on a bytes-like object
は、私はその周りに行くことができる方法はありますか?同様に、xlsxファイルを非バイナリにするか、電子メールにバイナリファイルを添付する関数があるかどうかを確認します。