MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / _make_request

Method _make_request

src/services/temp_mail.py:566–611  ·  view source on GitHub ↗

发送请求并返回 JSON 数据 Args: method: HTTP 方法 path: 请求路径(以 / 开头) **kwargs: 传递给 http_client.request 的额外参数 Returns: 响应 JSON 数据 Raises: EmailServiceError: 请求失败

(self, method: str, path: str, **kwargs)

Source from the content-addressed store, hash-verified

564 return fallback or str(hash(json.dumps(mail, sort_keys=True, ensure_ascii=False)))
565
566 def _make_request(self, method: str, path: str, **kwargs) -> Any:
567 """
568 发送请求并返回 JSON 数据
569
570 Args:
571 method: HTTP 方法
572 path: 请求路径(以 / 开头)
573 **kwargs: 传递给 http_client.request 的额外参数
574
575 Returns:
576 响应 JSON 数据
577
578 Raises:
579 EmailServiceError: 请求失败
580 """
581 base_url = self.config["base_url"].rstrip("/")
582 url = f"{base_url}{path}"
583
584 # 合并默认 admin headers
585 kwargs.setdefault("headers", {})
586 for k, v in self._admin_headers().items():
587 kwargs["headers"].setdefault(k, v)
588
589 try:
590 response = self.http_client.request(method, url, **kwargs)
591
592 if response.status_code >= 400:
593 error_msg = f"请求失败: {response.status_code}"
594 try:
595 error_data = response.json()
596 error_msg = f"{error_msg} - {error_data}"
597 except Exception:
598 error_msg = f"{error_msg} - {response.text[:200]}"
599 self.update_status(False, EmailServiceError(error_msg))
600 raise EmailServiceError(error_msg)
601
602 try:
603 return response.json()
604 except json.JSONDecodeError:
605 return {"raw_response": response.text}
606
607 except Exception as e:
608 self.update_status(False, e)
609 if isinstance(e, EmailServiceError):
610 raise
611 raise EmailServiceError(f"请求失败: {method} {path} - {e}")
612
613 def create_email(self, config: Dict[str, Any] = None) -> Dict[str, Any]:
614 """

Callers 5

_fetch_mails_onceMethod · 0.95
_fetch_mail_detailMethod · 0.95
create_emailMethod · 0.95
check_healthMethod · 0.95

Calls 5

_admin_headersMethod · 0.95
EmailServiceErrorClass · 0.85
requestMethod · 0.45
jsonMethod · 0.45
update_statusMethod · 0.45

Tested by

no test coverage detected