ファイルにアクセスできないです。
ディレクトリに、test.docxがあります。このtest.docxをメールで送りたいです。
def test1(): test2("test.docx") def test2(file): subject = "メール送付" message = "添付" from_email = settings.EMAIL_HOST_USER recipient_list = [ email ] message = EmailMessage(subject, message, from_email=from_email, to=recipient_list) message.attach(docx, 'contents', 'application/json; charset=UTF-8') message.send()
とコードを書いて実行しましたが、
test2メソッドはtest.docxという文字列にアクセスしてしまい、docxにはアクセスしていません。
def test1(): test2(open("test.docx"))
とコードを書きましたが、そうすると、
'_io.TextIOWrapper' object has no attribute 'encode' とエラーが出ました。
どのようにコードを修正したら、目的のことができますか?
回答1件
あなたの回答
tips
プレビュー