Hi I am trying to attach a pdf and when I do some sort of encoding issue pops up. I can send a csv file no problem it's only when I add the pdf (or another binary file like a gpg key) that this encoding issue comes up.
I saw issue 17 which seems similar to mine but that is fixed in the versions I am using right?
This is the code I am using, I've tried setting the disposition explicitly to 'attachment' as well as using the full file location for the file name.
csv_attachment = Attachment("%s.csv" % report.name, "text/csv", open(csv_loc, "rb"), 'attachment')
pdf_attachment = Attachment("%s.pdf" % report.name, "application/pdf", open(pdf_loc, "rb"), 'attachment')
body = render('mail/report.mak', {'user':user, 'report':report}, request)
message = Message(subject='Famoso Reporting - %s' % report.name,
sender='Famoso Admin <[email protected]>',
recipients=[user.email],
body=body,
attachments=[csv_attachment,pdf_attachment])
mailer.send(message)
Here is the traceback of the error:
Traceback (most recent call last):
File "/Users/rottaway/PyEnvs/famoso_reports/lib/python2.6/site-packages/waitress-0.8.1-py2.6.egg/waitress/channel.py", line 329, in service
task.service()
File "/Users/rottaway/PyEnvs/famoso_reports/lib/python2.6/site-packages/waitress-0.8.1-py2.6.egg/waitress/task.py", line 173, in service
self.execute()
File "/Users/rottaway/PyEnvs/famoso_reports/lib/python2.6/site-packages/waitress-0.8.1-py2.6.egg/waitress/task.py", line 380, in execute
app_iter = self.channel.server.application(env, start_response)
File "/Users/rottaway/PyEnvs/famoso_reports/lib/python2.6/site-packages/pyramid/router.py", line 187, in call
response = self.handle_request(request)
File "/Users/rottaway/PyEnvs/famoso_reports/lib/python2.6/site-packages/pyramid/tweens.py", line 20, in excview_tween
response = handler(request)
File "/Users/rottaway/PyEnvs/famoso_reports/lib/python2.6/site-packages/pyramid_tm-0.4-py2.6.egg/pyramid_tm/init.py", line 102, in tm_tween
return response
File "/Users/rottaway/PyEnvs/famoso_reports/lib/python2.6/site-packages/transaction/_manager.py", line 96, in exit
self.commit()
File "/Users/rottaway/PyEnvs/famoso_reports/lib/python2.6/site-packages/transaction/_manager.py", line 89, in commit
return self.get().commit()
File "/Users/rottaway/PyEnvs/famoso_reports/lib/python2.6/site-packages/transaction/_transaction.py", line 342, in commit
reraise(t, v, tb)
File "/Users/rottaway/PyEnvs/famoso_reports/lib/python2.6/site-packages/transaction/_transaction.py", line 333, in commit
self._commitResources()
File "/Users/rottaway/PyEnvs/famoso_reports/lib/python2.6/site-packages/transaction/_transaction.py", line 473, in _commitResources
reraise(t, v, tb)
File "/Users/rottaway/PyEnvs/famoso_reports/lib/python2.6/site-packages/transaction/_transaction.py", line 455, in _commitResources
rm.tpc_finish(self)
File "/Users/rottaway/PyEnvs/famoso_reports/lib/python2.6/site-packages/repoze/sendmail/delivery.py", line 70, in tpc_finish
self.callable(*self.args)
File "/Users/rottaway/PyEnvs/famoso_reports/lib/python2.6/site-packages/repoze/sendmail/mailer.py", line 53, in send
message = encode_message(message)
File "/Users/rottaway/PyEnvs/famoso_reports/lib/python2.6/site-packages/repoze/sendmail/encoding.py", line 101, in encode_message
return message.as_string().encode('ascii')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb5 in position 1476: ordinal not in range(128)