import requests class ApolloClient(object): def __init__(self, base_url): self.base_url = base_url def get_config(self, app_id: str, cluster: str = "default", namespace: str = "application"): url = f"{self.base_url}/configs/{app_id}/{cluster}/{namespace}" print(f"请求的Apollo地址为: {url}") response = requests.get(url) return response.json() def get_value(self, app_id: str, cluster: str = "default", namespace: str = "application", key: str = None): if not key: raise ValueError("Key not empty") config_json = self.get_config(app_id=app_id, cluster=cluster, namespace=namespace) return config_json['configurations'][key]