1. import json
  2. def load_auth_tokens(config_file):
  3. """
  4. Loads authentication tokens from a JSON configuration file.
  5. Args:
  6. config_file (str): Path to the JSON configuration file.
  7. Returns:
  8. dict: A dictionary containing authentication tokens. Returns an empty dictionary if the file is not found or invalid.
  9. """
  10. try:
  11. with open(config_file, 'r') as f:
  12. config = json.load(f)
  13. return config
  14. except FileNotFoundError:
  15. print(f"Error: Configuration file not found: {config_file}")
  16. return {}
  17. except json.JSONDecodeError:
  18. print(f"Error: Invalid JSON format in {config_file}")
  19. return {}
  20. if __name__ == '__main__':
  21. #Example usage
  22. tokens = load_auth_tokens('auth_config.json') # Replace with your config file
  23. print(tokens)

Add your comment