From ade34b4701c6d8e4e19a163f70dbd30665dca30a Mon Sep 17 00:00:00 2001 From: Elmer Thomas Date: Wed, 28 Oct 2015 16:32:12 -0700 Subject: [PATCH] Fixes issue 104, timeout via URLError --- sendgrid/sendgrid.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sendgrid/sendgrid.py b/sendgrid/sendgrid.py index f62dd9e21..164d25fdb 100644 --- a/sendgrid/sendgrid.py +++ b/sendgrid/sendgrid.py @@ -6,9 +6,11 @@ import urllib.request as urllib_request from urllib.parse import urlencode from urllib.error import HTTPError + from urllib.error import URLError except ImportError: # Python 2 import urllib2 as urllib_request from urllib2 import HTTPError + from urllib2 import URLError from urllib import urlencode from .exceptions import SendGridClientError, SendGridServerError @@ -121,6 +123,8 @@ def _legacy_send(self, message): return self._make_request(message) except HTTPError as e: return e.code, e.read() + except URLError as e: + return 408, e.reason except timeout as e: return 408, e @@ -134,5 +138,7 @@ def _raising_send(self, message): raise SendGridServerError(e.code, e.read()) else: assert False + except URLError as e: + raise SendGridClientError(408, 'Request timeout') except timeout as e: raise SendGridClientError(408, 'Request timeout')