获取特定源的API密钥。 参数: source_name: 接口供应商名称 返回: API密钥,如果请求失败则返回None
(self, source_name: str)
| 15 | self.base_url = base_url.rstrip('/') |
| 16 | |
| 17 | def get_api_key(self, source_name: str) -> Optional[str]: |
| 18 | """获取特定源的API密钥。 |
| 19 | |
| 20 | 参数: |
| 21 | source_name: 接口供应商名称 |
| 22 | |
| 23 | 返回: |
| 24 | API密钥,如果请求失败则返回None |
| 25 | """ |
| 26 | try: |
| 27 | response = requests.post( |
| 28 | f"{self.base_url}/get_apikey", |
| 29 | json={"source_name": source_name}, |
| 30 | timeout=5 |
| 31 | ) |
| 32 | if response.status_code == 200: |
| 33 | return response.json().get("api_key") |
| 34 | else: |
| 35 | print(f"获取API密钥失败: {response.status_code} - {response.text}") |
| 36 | return None |
| 37 | except Exception as e: |
| 38 | print(f"获取API密钥时出错: {str(e)}") |
| 39 | return None |
| 40 | |
| 41 | def notice_api_key_usage( |
| 42 | self, |
no outgoing calls
no test coverage detected