【问题标题】:Python cannot find file to send as email attachmentPython 找不到要作为电子邮件附件发送的文件
【发布时间】:2015-07-08 21:48:39
【问题描述】:

我正在使用 Python3 和 mime.multipart 发送附件。我能够成功发送附件。但是今天,当我在 WINSCP 中看到它明显存在时,我收到一个错误消息,说文件不存在。这是权限问题吗?此外,当我列出目录的内容时,文件不会显示。怎么回事?

【问题讨论】:

  • 我将说明明显的检查:python 正在查找的目录已更改(检查),或者文件已移动(检查)
  • 列出了同一文件夹中具有相同权限的其他文件,但不是我要附加的文件。粘贴一些调试语句: >>写入 /home/user/programs/automation/files/Acme_Insights.xslx >>在文件目录中..(glob.glob) ['/home/user/programs/automation/files/test. txt'](acme 没有列出)>>文件“process_insights_python.py”,第 885 行,在 main fp = open(fileToSend,“rb”) FileNotFoundError: [Errno 2] 没有这样的文件或目录:“/home/user /programs/automation/files/Acme_Insights.xslx"

标签: python python-3.x file-upload email-attachments mime-message


【解决方案1】:

写入文件后我没有关闭流。所以代码找不到文件。但是,当脚本完成时,流将被强制关闭,我会在文件夹中看到该文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-26
    • 2015-06-19
    • 2016-04-29
    • 2013-03-19
    • 2012-06-15
    • 2023-03-23
    • 1970-01-01
    相关资源
    最近更新 更多