Make an HTTP request and deserialize the response as JSON. Optionally decode the deserialized json dict into a decoded object. :param method: request method :type method: str :param timeout: timeout in seconds :type timeout: float :param auth
(self,
method,
timeout=None,
auth=None,
payload=None,
decoder=None,
params=None,
**kwargs)
| 296 | raise MesosException('Request failed', err) |
| 297 | |
| 298 | def request_json(self, |
| 299 | method, |
| 300 | timeout=None, |
| 301 | auth=None, |
| 302 | payload=None, |
| 303 | decoder=None, |
| 304 | params=None, |
| 305 | **kwargs): |
| 306 | """ |
| 307 | Make an HTTP request and deserialize the response as JSON. Optionally |
| 308 | decode the deserialized json dict into a decoded object. |
| 309 | |
| 310 | :param method: request method |
| 311 | :type method: str |
| 312 | :param timeout: timeout in seconds |
| 313 | :type timeout: float |
| 314 | :param auth: auth scheme for the request |
| 315 | :type auth: requests.auth.AuthBase |
| 316 | :param payload: json payload in the request |
| 317 | :type payload: dict[str, T] | str |
| 318 | :param decoder: decoder for json response |
| 319 | :type decoder: (dict) -> T |
| 320 | :param params: additional params to include in the request |
| 321 | :type params: str | dict[str, T] |
| 322 | :param kwargs: additional arguments to pass to requests.request |
| 323 | :type kwargs: dict[str, T] |
| 324 | :return: JSON response |
| 325 | :rtype: dict[str, T] |
| 326 | """ |
| 327 | resp = self.request(method=method, |
| 328 | timeout=timeout, |
| 329 | auth=auth, |
| 330 | json=payload, |
| 331 | additional_headers=REQUEST_JSON_HEADERS, |
| 332 | params=params, |
| 333 | **kwargs) |
| 334 | |
| 335 | try: |
| 336 | json_dict = ujson.loads(resp.text) |
| 337 | except ValueError as exception: |
| 338 | raise MesosException( |
| 339 | 'could not load JSON from "{data}"'.format(data=resp.text), |
| 340 | exception) |
| 341 | |
| 342 | if decoder is not None: |
| 343 | return decoder(json_dict) |
| 344 | |
| 345 | return json_dict |
| 346 | |
| 347 | def get_json(self, |
| 348 | timeout=None, |