fix(config): Correct API key filename and improve logging
- Changes the expected API key filename from 'api_key.txt' to 'gemini_api_key.txt' to match the project standard. - Enhances logging to output the absolute path when an API key file is not found, simplifying future debugging.
This commit is contained in:
11
config.py
11
config.py
@@ -21,7 +21,7 @@ import logging
|
|||||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
CREDENTIALS_FILE = os.path.join(BASE_DIR, "service_account.json")
|
CREDENTIALS_FILE = os.path.join(BASE_DIR, "service_account.json")
|
||||||
API_KEY_FILE = os.path.join(BASE_DIR, "api_key.txt") # OpenAI
|
API_KEY_FILE = os.path.join(BASE_DIR, "gemini_api_key.txt") # Standard für Gemini
|
||||||
SERP_API_KEY_FILE = os.path.join(BASE_DIR, "serpApiKey.txt")
|
SERP_API_KEY_FILE = os.path.join(BASE_DIR, "serpApiKey.txt")
|
||||||
GENDERIZE_API_KEY_FILE = os.path.join(BASE_DIR, "genderize_API_Key.txt")
|
GENDERIZE_API_KEY_FILE = os.path.join(BASE_DIR, "genderize_API_Key.txt")
|
||||||
BRANCH_MAPPING_FILE = None
|
BRANCH_MAPPING_FILE = None
|
||||||
@@ -509,19 +509,20 @@ class Config:
|
|||||||
def _load_key_from_file(filepath):
|
def _load_key_from_file(filepath):
|
||||||
"""Hilfsfunktion zum Laden eines Schluessels aus einer Datei."""
|
"""Hilfsfunktion zum Laden eines Schluessels aus einer Datei."""
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
abs_path = os.path.abspath(filepath)
|
||||||
try:
|
try:
|
||||||
with open(filepath, "r", encoding="utf-8") as f:
|
with open(abs_path, "r", encoding="utf-8") as f:
|
||||||
key = f.read().strip()
|
key = f.read().strip()
|
||||||
if key:
|
if key:
|
||||||
return key
|
return key
|
||||||
else:
|
else:
|
||||||
logger.warning(f"Datei '{filepath}' ist leer.")
|
logger.warning(f"API key file is empty: '{abs_path}'")
|
||||||
return None
|
return None
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
logger.info(f"API-Schluesseldatei '{filepath}' nicht gefunden.")
|
logger.warning(f"API key file not found at path: '{abs_path}'")
|
||||||
return None
|
return None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"FEHLER beim Lesen der Schluesseldatei '{filepath}': {e}")
|
logger.error(f"Error reading key file '{abs_path}': {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user