[fix] Catch ConnectionError while checking gravatar_url
This commit is contained in:
parent
3d7b9cfe77
commit
6aaa6ce17d
1 changed files with 7 additions and 3 deletions
|
|
@ -128,10 +128,14 @@ def has_gravatar(email):
|
|||
return
|
||||
|
||||
gravatar_url = "https://secure.gravatar.com/avatar/{hash}?d=404&s=200".format(hash=md5.md5(email).hexdigest())
|
||||
if requests.get(gravatar_url).status_code==404:
|
||||
try:
|
||||
res = requests.get(gravatar_url)
|
||||
if res.status_code==404:
|
||||
return ''
|
||||
else:
|
||||
return gravatar_url
|
||||
except requests.exceptions.ConnectionError:
|
||||
return ''
|
||||
else:
|
||||
return gravatar_url
|
||||
|
||||
def get_gravatar(email):
|
||||
gravatar_url = has_gravatar(email)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue