From 4a55e34cb1a024e9a2b0b355e9ecdc204c8ad592 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 11 Apr 2016 13:46:32 -0400 Subject: [PATCH] Fail safe when gravatar is done Fixes #1358 --- avatars/avatars.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/avatars/avatars.py b/avatars/avatars.py index 220cae9cb..eaf58bc52 100644 --- a/avatars/avatars.py +++ b/avatars/avatars.py @@ -1,5 +1,10 @@ import hashlib import math +import logging + +from requests.exceptions import RequestException + +logger = logging.getLogger(__name__) class Avatar(object): def __init__(self, app=None): @@ -32,10 +37,13 @@ class BaseAvatar(object): if url is not None: # Try to load the gravatar. If we get a non-404 response, then we use it in place of # the CSS avatar. - response = self.http_client.get(url) - if response.status_code == 200: - return """%s""" % (url, size, size, kind) + try: + response = self.http_client.get(url, timeout=5) + if response.status_code == 200: + return """%s""" % (url, size, size, kind) + except RequestException: + logger.exception('Could not retrieve avatar for user %s', name) radius = '50%' if kind == 'team' else '0%' letter = 'Ω' if kind == 'team' and data['name'] == 'owners' else data['name'].upper()[0]