Skip to content

Commit aa3d5c1

Browse files
committed
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.
1 parent 64eaec3 commit aa3d5c1

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

sendgrid/message.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ def set_replyto(self, replyto):
119119
self.reply_to = replyto
120120

121121
def add_attachment(self, name, file_):
122+
if sys.version_info < (3, 0) and isinstance(name, unicode):
123+
name = name.encode('utf-8')
122124
if isinstance(file_, str): # filepath
123125
with open(file_, 'rb') as f:
124126
self.files[name] = f.read()

0 commit comments

Comments
 (0)