Python错误:(2,'No this file or directory')在Python中电子邮件文件时

2024-04-25 03:30:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过EmailMessage发送一个文件,但是我得到了一个错误No such file or directory。该文件位于上述目录中,因此 为什么我不能通过电子邮件发送文件?在

from django.core.mail import send_mail, EmailMessage

def email_file(recipient, title, email_msg, file_name):
    try:
        msg = EmailMessage(title, email_msg, to=recipient)
        msg.attach_file(file_name)
        msg.send()
    except Exception as exception:
        print exception.args

if __name__ == '__main__':
    excel_file = '/home/geeks/test.pdf'
    recipient = 'email'
    email_msg = 'Please find placement report of this week'
    title = 'Status Report'
    email_file(recipient, title, email_msg, excel_file)

文件权限为

^{pr2}$

Tags: 文件nonamesendtitleemail错误exception
1条回答
网友
1楼 · 发布于 2024-04-25 03:30:40
No such file or directory

它本身就表明了答案。在

您的文件在指定的路径中不存在,或者没有足够的权限读取文件。在

相关问题 更多 >