Make an HTTP request by calling self._request with backoff retry. :param method: request method :type method: str :param additional_headers: additional headers to include in the request :type additional_headers: dict[str, str] :param retry: boolean i
(self,
method,
additional_headers=None,
retry=True,
timeout=None,
auth=None,
use_gzip_encoding=None,
params=None,
max_attempts=None,
**kwargs)
| 221 | raise MesosHTTPException(response) |
| 222 | |
| 223 | def request(self, |
| 224 | method, |
| 225 | additional_headers=None, |
| 226 | retry=True, |
| 227 | timeout=None, |
| 228 | auth=None, |
| 229 | use_gzip_encoding=None, |
| 230 | params=None, |
| 231 | max_attempts=None, |
| 232 | **kwargs): |
| 233 | """ |
| 234 | Make an HTTP request by calling self._request with backoff retry. |
| 235 | |
| 236 | :param method: request method |
| 237 | :type method: str |
| 238 | :param additional_headers: additional headers to include in the request |
| 239 | :type additional_headers: dict[str, str] |
| 240 | :param retry: boolean indicating whether to retry if the request fails |
| 241 | :type retry: boolean |
| 242 | :param timeout: timeout in seconds, overrides default_timeout_secs |
| 243 | :type timeout: float |
| 244 | :param timeout: timeout in seconds |
| 245 | :type timeout: float |
| 246 | :param auth: auth scheme for the request |
| 247 | :type auth: requests.auth.AuthBase |
| 248 | :param use_gzip_encoding: boolean indicating whether to pass gzip |
| 249 | encoding in the request headers or not |
| 250 | :type use_gzip_encoding: boolean | None |
| 251 | :param params: additional params to include in the request |
| 252 | :type params: str | dict[str, T] | None |
| 253 | :param max_attempts: maximum number of attempts to try for any request |
| 254 | :type max_attempts: int |
| 255 | :param kwargs: additional arguments to pass to requests.request |
| 256 | :type kwargs: dict[str, T] |
| 257 | :return: HTTP response |
| 258 | :rtype: requests.Response |
| 259 | """ |
| 260 | request = self._request |
| 261 | |
| 262 | if retry: |
| 263 | if max_attempts is None: |
| 264 | max_attempts = self.default_max_attempts |
| 265 | |
| 266 | # We retry only when it makes sense: either due to a network |
| 267 | # partition (e.g. connection errors) or if the request failed |
| 268 | # due to a server error such as 500s, timeouts, and so on. |
| 269 | request = tenacity.retry( |
| 270 | stop=tenacity.stop_after_attempt(max_attempts), |
| 271 | wait=tenacity.wait_exponential(), |
| 272 | retry=tenacity.retry_if_exception_type(( |
| 273 | requests.exceptions.Timeout, |
| 274 | requests.exceptions.ConnectionError, |
| 275 | MesosServiceUnavailableException, |
| 276 | MesosInternalServerErrorException, |
| 277 | )), |
| 278 | reraise=True, |
| 279 | )(request) |
| 280 |