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

Method request

src/core/http_client.py:85–145  ·  view source on GitHub ↗

发送 HTTP 请求 Args: method: HTTP 方法 (GET, POST, PUT, DELETE, etc.) url: 请求 URL **kwargs: 其他请求参数 Returns: Response 对象 Raises: HTTPClientError: 请求失败

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

Source from the content-addressed store, hash-verified

83 return self._session
84
85 def request(
86 self,
87 method: str,
88 url: str,
89 **kwargs
90 ) -> Response:
91 """
92 发送 HTTP 请求
93
94 Args:
95 method: HTTP 方法 (GET, POST, PUT, DELETE, etc.)
96 url: 请求 URL
97 **kwargs: 其他请求参数
98
99 Returns:
100 Response 对象
101
102 Raises:
103 HTTPClientError: 请求失败
104 """
105 # 设置默认参数
106 kwargs.setdefault("timeout", self.config.timeout)
107 kwargs.setdefault("allow_redirects", self.config.follow_redirects)
108
109 # 添加代理配置
110 if self.proxies and "proxies" not in kwargs:
111 kwargs["proxies"] = self.proxies
112
113 last_exception = None
114 for attempt in range(self.config.max_retries):
115 try:
116 response = self.session.request(method, url, **kwargs)
117
118 # 检查响应状态码
119 if response.status_code >= 400:
120 logger.warning(
121 f"HTTP {response.status_code} for {method} {url}"
122 f" (attempt {attempt + 1}/{self.config.max_retries})"
123 )
124
125 # 如果是服务器错误,重试
126 if response.status_code >= 500 and attempt < self.config.max_retries - 1:
127 time.sleep(self.config.retry_delay * (attempt + 1))
128 continue
129
130 return response
131
132 except (cffi_requests.RequestsError, ConnectionError, TimeoutError) as e:
133 last_exception = e
134 logger.warning(
135 f"请求失败: {method} {url} (attempt {attempt + 1}/{self.config.max_retries}): {e}"
136 )
137
138 if attempt < self.config.max_retries - 1:
139 time.sleep(self.config.retry_delay * (attempt + 1))
140 else:
141 break
142

Callers 15

getMethod · 0.95
postMethod · 0.95
putMethod · 0.95
deleteMethod · 0.95
headMethod · 0.95
optionsMethod · 0.95
patchMethod · 0.95
send_openai_requestMethod · 0.45
_make_requestMethod · 0.45
_make_requestMethod · 0.45
_make_requestMethod · 0.45

Calls 3

HTTPClientErrorClass · 0.85
warningMethod · 0.80
sleepMethod · 0.80

Tested by

no test coverage detected