From 6beb2ddd74e4b424a01c72d649b3004def45593a Mon Sep 17 00:00:00 2001 From: Scott Sexton Date: Fri, 13 Dec 2013 13:47:54 -0600 Subject: [PATCH 1/2] Fixed UTF-8 encoding crash in web module --- sendgrid/transport/web.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sendgrid/transport/web.py b/sendgrid/transport/web.py index 1d543a30d..94e38e400 100644 --- a/sendgrid/transport/web.py +++ b/sendgrid/transport/web.py @@ -85,7 +85,11 @@ def send(self, message): for key in optional_params: if optional_params[key]: - data[key] = optional_params[key] + val = optional_params[key] + if isinstance(val, unicode): + data[key] = val.encode('utf-8') + elif isinstance(val, str): + data[key] = val.decode('utf-8') data = urllib.urlencode(data, 1) req = urllib2.Request(url, data) From 8647e15db69af9cda6fd9ef3a712021705d1c128 Mon Sep 17 00:00:00 2001 From: Scott Sexton Date: Tue, 17 Dec 2013 12:33:25 -0600 Subject: [PATCH 2/2] Just do the encode --- sendgrid/transport/web.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/sendgrid/transport/web.py b/sendgrid/transport/web.py index 94e38e400..d2d75cb3a 100644 --- a/sendgrid/transport/web.py +++ b/sendgrid/transport/web.py @@ -85,11 +85,9 @@ def send(self, message): for key in optional_params: if optional_params[key]: - val = optional_params[key] - if isinstance(val, unicode): - data[key] = val.encode('utf-8') - elif isinstance(val, str): - data[key] = val.decode('utf-8') + data[key] = optional_params[key] + if isinstance(data[key], unicode): + data[key] = data[key].encode('utf-8') data = urllib.urlencode(data, 1) req = urllib2.Request(url, data)