Django 如何在google app engine python发送邮件功能中附加pdf?

Django 如何在google app engine python发送邮件功能中附加pdf?,django,python-2.7,google-app-engine,Django,Python 2.7,Google App Engine,我找不到任何关于如何在python(google app engine)send_mail函数中附加位于我的站点根文件夹中的文件(pdf)的示例 url_test = "https://mywebsite.com/pdf/test.pdf" test_file = urlfetch.fetch(url_test) if test_file.status_code == 200: test_document = test_file.content

我找不到任何关于如何在python(google app engine)send_mail函数中附加位于我的站点根文件夹中的文件(pdf)的示例

 url_test = "https://mywebsite.com/pdf/test.pdf"
      test_file = urlfetch.fetch(url_test)

      if test_file.status_code == 200:
            test_document = test_file.content
      mail.send_mail(sender=EMAIL_SENDER,
                  to=['test@test.com'],
                  subject=subject,
                  body=theBody,
                  attachments=[("testing",test_document)])
已决定尝试使用EmailMessage:

 message = mail.EmailMessage( sender=EMAIL_SENDER, 
 subject=subject,body=theBody,to=['myemail@gmail.com'],attachments= 
 [(attachname, blob.archivoBlob)])
 message.send()
上面的blob附件已成功发送,但附加具有相对路径的文件时始终显示“无效附件”

在调试过程中,我还尝试通过执行以下操作查看文件是否正在读取:

 logging.info(new_file)
它似乎正在读取文件,因为它输出了一些unicode字符


请帮助我为什么不能附加PDF而我可以附加blob

调用附件时,必须在文件标题上注明文件类型,例如附件=[('testing.PDF',new_File)])。查看此

您是在标准环境还是灵活环境下运行?@LundinCast运行标准环境由于记录新\u文件的输出是一些unicode字符,而不是PDF的实际内容,这意味着问题不一定与将PDF附加到发送\u邮件函数()有关。在我看来,文件没有从该位置正确读取。这解释了预期的文件类型。此外,调用附件时,必须在文件标题上注明文件类型,例如附件=[('testing.pdf',new_file)])。查看此@oakinlaja thx!这就是问题所在!我忘了提到“.pdf”扩展名。在那之后,它起了作用
 logging.info(new_file)