def service_request(self, service, url, method="GET", body=None, response_body_type="", headers=None, **kwargs): """ The method that sends the request and handles the response returned. This assumes that the response arrives in the HTTP response. :param url: The URL to which the request should be sent :param method: Which HTTP method to use :param body: A message body if any :param response_body_type: The expected format of the body of the return message :param http_args: Arguments for the HTTP client :return: A cls or ResponseMessage instance or the HTTP response instance if no response body was expected. """ if headers is None: headers = {} logger.debug(REQUEST_INFO.format(url, method, body, headers)) try: resp = self.http(url, method, data=body, headers=headers) except Exception as err: logger.error('Exception on request: {}'.format(err)) raise if "keyjar" not in kwargs: kwargs["keyjar"] = service.service_context.keyjar if not response_body_type: response_body_type = service.response_body_type if 300 <= resp.status_code < 400: return {'http_response': resp} if response_body_type == 'html': return resp.text response = self.parse_request_response(service, resp, response_body_type, **kwargs) if 'error' in response: pass else: service.update_service_context(response, **kwargs) return response
def service_request(self, service, url, method="GET", body=None, response_body_type="", headers=None, **kwargs): """ The method that sends the request and handles the response returned. This assumes that the response arrives in the HTTP response. :param url: The URL to which the request should be sent :param method: Which HTTP method to use :param body: A message body if any :param response_body_type: The expected format of the body of the return message :param httpc_params: Arguments for the HTTP client :return: A cls or ResponseMessage instance or the HTTP response instance if no response body was expected. """ if headers is None: headers = {} logger.debug(REQUEST_INFO.format(url, method, body, headers)) try: response = service.get_response_ext(url, method, body, response_body_type, headers, **kwargs) except AttributeError: response = self.get_response(service, url, method, body, response_body_type, headers, **kwargs) if 'error' in response: pass else: try: kwargs['key'] = kwargs['state'] except KeyError: pass service.update_service_context(response, **kwargs) return response