diff --git a/profiles/__init__.py b/profiles/__init__.py index af10643..f4ce2e3 100644 --- a/profiles/__init__.py +++ b/profiles/__init__.py @@ -191,7 +191,10 @@ def logout(): @app.route("/image/", methods=["GET"]) def image(uid): try: - return get_image(uid) + response = get_image(uid) + if isinstance(response, str): + return redirect(response, code=302) + return response except BadQueryError as bqe: return render_template("404.html", message=bqe, **app.config['DATADOG_RUM_CONFIG']), 404 diff --git a/profiles/ldap.py b/profiles/ldap.py index 423db13..8ac8e71 100644 --- a/profiles/ldap.py +++ b/profiles/ldap.py @@ -7,7 +7,6 @@ import ldap import requests from PIL import Image -from flask import redirect from profiles import _ldap @@ -414,7 +413,7 @@ def get_image(uid): github = account.github twitter = account.twitterName except KeyError: - return redirect(get_gravatar(), code=302) + return get_gravatar() # Return stored Image if image: @@ -425,7 +424,7 @@ def get_image(uid): try: with urllib.request.urlopen(url) as gravatar: if gravatar.getcode() == 200: - return redirect(url, code=302) + return url except urllib.error.HTTPError: pass @@ -448,7 +447,7 @@ def get_image(uid): pass # Fall back to default - return redirect(get_gravatar(), code=302) + return get_gravatar() @lru_cache(maxsize=1024)