From d16628195d8229d3843bdd38acc96c600330e2da Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Mon, 18 Jul 2022 21:02:46 +0200 Subject: [PATCH] Tweak key fetching --- app/httpsig.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/httpsig.py b/app/httpsig.py index b547ba2..1d00f0b 100644 --- a/app/httpsig.py +++ b/app/httpsig.py @@ -93,7 +93,13 @@ async def _get_public_key(db_session: AsyncSession, key_id: str) -> Key: # Without signing the request as if it's the first contact, the 2 servers # might race to fetch each other key - actor = await ap.fetch(key_id, disable_httpsig=True) + try: + actor = await ap.fetch(key_id, disable_httpsig=True) + except httpx.HTTPStatusError as http_err: + if http_err.response.status_code in [401, 403]: + actor = await ap.fetch(key_id, disable_httpsig=False) + else: + raise if actor["type"] == "Key": # The Key is not embedded in the Person k = Key(actor["owner"], actor["id"])