kopia lustrzana https://github.com/snarfed/bridgy-fed
handle SSL failures when fetching arbitrary URLs
fixes https://console.cloud.google.com/errors/CJOuzd2b1sehPApull/59/head
rodzic
2e33354c27
commit
6e7c2008e9
|
@ -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)
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue