From aa3d5c10c292b7580738cd5782e6329dba1d6e9c Mon Sep 17 00:00:00 2001 From: Bradley Gordon Date: Wed, 15 Oct 2014 12:10:49 -0600 Subject: [PATCH] Encode unicode object file attachment names to Python str objects Currently, the method sendgrid.message.Mail.add_attachment_stream encodes unicode object filenames to Python str objects. However, the method sendgrid.message.Mail.add_attachment does not do the same encoding. This commit fixes that. --- sendgrid/message.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sendgrid/message.py b/sendgrid/message.py index 22ce3a795..a0a6a459d 100644 --- a/sendgrid/message.py +++ b/sendgrid/message.py @@ -119,6 +119,8 @@ def set_replyto(self, replyto): self.reply_to = replyto def add_attachment(self, name, file_): + if sys.version_info < (3, 0) and isinstance(name, unicode): + name = name.encode('utf-8') if isinstance(file_, str): # filepath with open(file_, 'rb') as f: self.files[name] = f.read()