handle SSL failures when fetching arbitrary URLs

fixes https://console.cloud.google.com/errors/CJOuzd2b1sehPA
pull/59/head
Ryan Barrett 2019-04-10 08:08:02 -07:00
rodzic 2e33354c27
commit 6e7c2008e9
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 11 dodań i 1 usunięć

Wyświetl plik

@ -79,7 +79,11 @@ def _requests_fn(fn, url, parse_json=False, **kwargs):
"""Wraps requests.* and adds raise_for_status() and User-Agent."""
kwargs.setdefault('headers', {}).update(HEADERS)
resp = fn(url, **kwargs)
try:
resp = fn(url, **kwargs)
except (requests.ConnectionError, requests.Timeout) as e:
logging.warning(url, exc_info=True)
raise exc.HTTPBadGateway(unicode(e))
logging.info('Got %s headers:%s', resp.status_code, resp.headers)
type = content_type(resp)

Wyświetl plik

@ -58,3 +58,9 @@ class CommonTest(testutil.TestCase):
def test_get_as2_not_acceptable(self, mock_get):
with self.assertRaises(exc.HTTPBadGateway):
resp = common.get_as2('http://orig')
@mock.patch('requests.get', side_effect=requests.exceptions.SSLError)
def test_get_ssl_error(self, mock_get):
with self.assertRaises(exc.HTTPBadGateway):
resp = common.get_as2('http://orig')