From 12fa6c41188aad460bf3552023d3988e24365205 Mon Sep 17 00:00:00 2001 From: Patrick Huck Date: Wed, 16 Oct 2024 19:27:37 -0500 Subject: [PATCH] fall back on PMG_MAPI_KEY (#1841) * fall back on PMG_MAPI_KEY * client: add apikey to error msg * client: allow no apikey through --- mpcontribs-client/mpcontribs/client/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mpcontribs-client/mpcontribs/client/__init__.py b/mpcontribs-client/mpcontribs/client/__init__.py index 5e83250e6..5fffdcd67 100644 --- a/mpcontribs-client/mpcontribs/client/__init__.py +++ b/mpcontribs-client/mpcontribs/client/__init__.py @@ -61,6 +61,7 @@ from plotly.express._chart_types import line as line_chart from cachetools import cached, LRUCache from cachetools.keys import hashkey +from pymatgen.core import SETTINGS RETRIES = 3 MAX_WORKERS = 3 @@ -886,7 +887,9 @@ def __init__( host = os.environ.get("MPCONTRIBS_API_HOST", DEFAULT_HOST) if not apikey: - apikey = os.environ.get("MPCONTRIBS_API_KEY") + apikey = os.environ.get("MPCONTRIBS_API_KEY", SETTINGS.get("PMG_MAPI_KEY")) + if apikey and len(apikey) != 32: + raise MPContribsClientError(f"Invalid API key: {apikey}") if apikey and headers: apikey = None