Guest User

Untitled

a guest
Dec 14th, 2017
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. Subject: test simple message
  2.  
  3. It's a test.
  4.  
  5. -- Best regards.
  6.  
  7. text = ''
  8. for attachment in self.attachments_pool:
  9. text+='Removed ' + attachment.getFilename() +' with hash: ' + attachment.getHash() + 'n'
  10. text = MIMEText(text, 'plain')
  11. self.msg.attach(text)
  12.  
  13. Traceback (most recent call last):
  14. File "/usr/lib/python3.5/email/message.py", line 209, in attach
  15. self._payload.append(payload)
  16. AttributeError: 'str' object has no attribute 'append'
  17.  
  18. During handling of the above exception, another exception occurred:
  19.  
  20. Traceback (most recent call last):
  21. File "msg_parser.py", line 386, in <module>
  22. raise e
  23. File "msg_parser.py", line 376, in <module>
  24. main()
  25. File "msg_parser.py", line 369, in main
  26. msg_handler.handle()
  27. File "msg_parser.py", line 329, in handle
  28. self.msg.attach(text)
  29. File "/usr/lib/python3.5/email/message.py", line 211, in attach
  30. raise TypeError("Attach is not valid on a message with a"
  31. TypeError: Attach is not valid on a message with a non-multipart payload
  32.  
  33. #!/usr/bin/env python3
  34. import email.policy
  35.  
  36. msg = email.message_from_string("""From [email protected]
  37. Subject: test simple message
  38.  
  39. It's a test.
  40.  
  41. -- Best regards.""", policy=email.policy.default)
  42.  
  43. msg.set_content("Заменили текст.")
  44.  
  45. print(msg)
  46.  
  47. Subject: test simple message
  48. Content-Type: text/plain; charset="utf-8"
  49. Content-Transfer-Encoding: base64
  50. MIME-Version: 1.0
  51.  
  52. 0JfQsNC80LXQvdC40LvQuCDRgtC10LrRgdGCLgo=
Add Comment
Please, Sign In to add comment