Esempio n. 1
0
File: test.py Progetto: n704/cst
 def test_init(self):
     import boto3
     from botocore.exceptions import EndpointConnectionError
     mock = Mock()
     mock.get_queue_by_name = Mock(side_effect=lambda QueueName: EndpointConnectionError())
     with patch.object(boto3, 'resource', return_value=mock) as mock_method:
         self.assertRaises(SQSError, lambda : SQS())
def test_immutable_file_storage_get_document_by_path_not_exist_in_bucket():
    backend = storage_backends.ImmutableFilesS3Boto3Storage()
    with patch.object(backend.connection, 'ObjectSummary') as mock:
        mock.side_effect = EndpointConnectionError(endpoint_url='/')
        document = backend.get_document_by_path('/thing.png')

    assert document is None
Esempio n. 3
0
    async def _get_response(self, request, operation_model, attempts):
        # This will return a tuple of (success_response, exception)
        # and success_response is itself a tuple of
        # (http_response, parsed_dict).
        # If an exception occurs then the success_response is None.
        # If no exception occurs then exception is None.
        try:
            # http request substituted too async one
            logger.debug("Sending http request: %s", request)
            history_recorder.record(
                'HTTP_REQUEST', {
                    'method': request.method,
                    'headers': request.headers,
                    'streaming': operation_model.has_streaming_input,
                    'url': request.url,
                    'body': request.body
                })
            http_response = await self._request(
                request.method, request.url, request.headers, request.body,
                operation_model.has_streaming_output)
        except aiohttp.ClientConnectionError as e:
            e.request = request  # botocore expects the request property

            # For a connection error, if it looks like it's a DNS
            # lookup issue, 99% of the time this is due to a misconfigured
            # region/endpoint so we'll raise a more specific error message
            # to help users.
            logger.debug("ConnectionError received when sending HTTP request.",
                         exc_info=True)

            if self._looks_like_dns_error(e):
                better_exception = EndpointConnectionError(
                    endpoint_url=request.url, error=e)
                return None, better_exception
            else:
                return None, e
        except aiohttp.http_exceptions.BadStatusLine:
            better_exception = ConnectionClosedError(endpoint_url=request.url,
                                                     request=request)
            return None, better_exception
        except Exception as e:
            logger.debug("Exception received when sending HTTP request.",
                         exc_info=True)
            return None, e

        # This returns the http_response and the parsed_data.
        response_dict = await convert_to_response_dict(http_response,
                                                       operation_model)

        http_response_record_dict = response_dict.copy()
        http_response_record_dict['streaming'] = \
            operation_model.has_streaming_output
        history_recorder.record('HTTP_RESPONSE', http_response_record_dict)

        parser = self._response_parser_factory.create_parser(
            operation_model.metadata['protocol'])
        parsed_response = parser.parse(response_dict,
                                       operation_model.output_shape)
        history_recorder.record('PARSED_RESPONSE', parsed_response)
        return (http_response, parsed_response), None
Esempio n. 4
0
 def test_find_usage_no_endpoint(self):
     exc = EndpointConnectionError(
         endpoint_url='https://efs.bad-region.amazonaws.com/'
     )
     mock_conn = Mock()
     with patch('%s.connect' % pb) as mock_connect:
         with patch('%s.paginate_dict' % pbm) as mock_paginate:
             mock_paginate.side_effect = exc
             cls = _EfsService(21, 43)
             cls.conn = mock_conn
             assert cls._have_usage is False
             cls.find_usage()
     assert cls._have_usage is True
     assert mock_connect.mock_calls == [call()]
     assert mock_paginate.mock_calls == [
         call(
             mock_conn.describe_file_systems,
             alc_marker_path=['NextMarker'],
             alc_data_path=['FileSystems'],
             alc_marker_param='Marker'
         )
     ]
     assert len(cls.limits) == 1
     usage = cls.limits['File systems'].get_current_usage()
     assert len(usage) == 0
Esempio n. 5
0
def test_describe_availability_zones_failed_endpoing_error(mocker):
    _test_describe_availability_zones_response(
        mocker,
        EndpointConnectionError(endpoint_url='https://efs.us-east-1.com'),
        None,
        1,
        desired_exception=mount_efs.FallbackException,
        desired_message='Could not connect to the endpoint')
def test_describe_mount_targets_failed_endpoint_error(mocker):
    _test_describe_mount_targets_response(
        mocker,
        EndpointConnectionError(endpoint_url="https://efs.us-east-1.com"),
        1,
        desired_exception=mount_efs.FallbackException,
        desired_message="Could not connect to the endpoint",
    )
Esempio n. 7
0
def test_get_s3_connection_error_endpoint(mocker):
    from botocore.exceptions import EndpointConnectionError

    fs = S3FileSystem(None, {"endpointurl": "https://example.com"})

    msg = "Unable to connect to 'https://example.com'."
    with pytest.raises(DvcException, match=msg):
        with fs._get_s3():
            raise EndpointConnectionError(endpoint_url="url")
Esempio n. 8
0
    def test_onecmd_connection_failure(self, mock_driver, mock_super):
        statement = "select * from another_table"
        mock_super.onecmd.side_effect = EndpointConnectionError(
            endpoint_url=None)
        mock_shell = QldbShell(None, mock_driver)

        mock_shell.onecmd(statement)

        self.assertRaises(SystemExit)
Esempio n. 9
0
def test_get_s3_connection_error(mocker):
    from botocore.exceptions import EndpointConnectionError

    fs = S3FileSystem(None, {})

    msg = "Unable to connect to 'AWS S3'."
    with pytest.raises(DvcException, match=msg):
        with fs._get_s3():
            raise EndpointConnectionError(endpoint_url="url")
Esempio n. 10
0
 def test_region_supported__unknown_supported_region_with_exception(
     self,
     list_repositories_mock,
     get_region_name_mock,
 ):
     get_region_name_mock.return_value = 'unknown-region'
     list_repositories_mock.side_effect = EndpointConnectionError(
         endpoint_url='xxx')
     region_supported = codecommit.region_supported()
     self.assertFalse(region_supported)
Esempio n. 11
0
    def send(self, request):
        try:
            proxy_url = self._proxy_config.proxy_url_for(request.url)
            manager = self._get_connection_manager(request.url, proxy_url)
            conn = manager.connection_from_url(request.url)
            self._setup_ssl_cert(conn, request.url, self._verify)

            request_target = self._get_request_target(request.url, proxy_url)
            urllib_response = conn.urlopen(
                method=request.method,
                url=request_target,
                body=request.body,
                headers=request.headers,
                retries=Retry(False),
                assert_same_host=False,
                preload_content=False,
                decode_content=False,
                chunked=self._chunked(request.headers),
            )

            http_response = botocore.awsrequest.AWSResponse(
                request.url,
                urllib_response.status,
                urllib_response.headers,
                urllib_response,
            )

            if not request.stream_output:
                # Cause the raw stream to be exhausted immediately. We do it
                # this way instead of using preload_content because
                # preload_content will never buffer chunked responses
                http_response.content

            return http_response
        except URLLib3SSLError as e:
            raise SSLError(endpoint_url=request.url, error=e)
        except (NewConnectionError, socket.gaierror) as e:
            raise EndpointConnectionError(endpoint_url=request.url, error=e)
        except ProxyError as e:
            raise ProxyConnectionError(proxy_url=proxy_url, error=e)
        except URLLib3ConnectTimeoutError as e:
            raise ConnectTimeoutError(endpoint_url=request.url, error=e)
        except URLLib3ReadTimeoutError as e:
            raise ReadTimeoutError(endpoint_url=request.url, error=e)
        except ProtocolError as e:
            raise ConnectionClosedError(
                error=e,
                request=request,
                endpoint_url=request.url
            )
        except Exception as e:
            message = 'Exception received when sending urllib3 HTTP request'
            logger.debug(message, exc_info=True)
            raise HTTPClientError(error=e)
Esempio n. 12
0
 def test_connectivity_failure(self, boto_mock):
     """
     test the test_connectivity method in case of failure
     """
     cloud_interface = CloudInterface('s3://bucket/path/to/dir',
                                      encryption=None)
     session_mock = boto_mock.Session.return_value
     s3_mock = session_mock.resource.return_value
     client_mock = s3_mock.meta.client
     # Raise the exception for the "I'm unable to reach amazon" event
     client_mock.head_bucket.side_effect = EndpointConnectionError(
         endpoint_url='bucket')
     assert cloud_interface.test_connectivity() is False
Esempio n. 13
0
 def test_find_usage_with_endpoint_connection_error(self):
     mock_conn = Mock()
     client_error = EndpointConnectionError(
         endpoint_url='https://firehose.bad-region.amazonaws.com/')
     mock_conn.list_delivery_streams.side_effect = client_error
     cls = _FirehoseService(21, 43)
     cls.conn = mock_conn
     with patch('%s.logger' % self.pbm, autospec=True) as mock_logger:
         cls.find_usage()
     error_msg = (
         'Caught exception when trying to use Firehose; '
         'perhaps the Firehose service is not available in this region?')
     assert call.error(error_msg, exc_info=1) in mock_logger.mock_calls
Esempio n. 14
0
    def _get_response(self, request, operation_model, attempts):
        # This will return a tuple of (success_response, exception)
        # and success_response is itself a tuple of
        # (http_response, parsed_dict).
        # If an exception occurs then the success_response is None.
        # If no exception occurs then exception is None.
        try:
            # http request substituted too async one
            botocore.endpoint.logger.debug("Sending http request: %s", request)

            # TODO: handle self.proxies
            resp = yield from self._request(request.method, request.url,
                                            request.headers, request.body)
            http_response = resp
        except aiohttp.errors.BadStatusLine:
            better_exception = ConnectionClosedError(endpoint_url=request.url,
                                                     request=request)
            return None, better_exception
        except aiohttp.errors.ClientConnectionError as e:
            e.request = request  # botocore expects the request property

            # For a connection error, if it looks like it's a DNS
            # lookup issue, 99% of the time this is due to a misconfigured
            # region/endpoint so we'll raise a more specific error message
            # to help users.
            botocore.endpoint.logger.debug(
                "ConnectionError received when "
                "sending HTTP request.",
                exc_info=True)

            if self._looks_like_dns_error(e):
                better_exception = EndpointConnectionError(
                    endpoint_url=request.url, error=e)
                return None, better_exception
            else:
                return None, e
        except Exception as e:
            botocore.endpoint.logger.debug(
                "Exception received when sending "
                "HTTP request.",
                exc_info=True)
            return None, e

        # This returns the http_response and the parsed_data.
        response_dict = yield from convert_to_response_dict(
            http_response, operation_model)
        parser = self._response_parser_factory.create_parser(
            operation_model.metadata['protocol'])
        parsed_response = parser.parse(response_dict,
                                       operation_model.output_shape)
        return (http_response, parsed_response), None
Esempio n. 15
0
    def test_delete_object_endpoint_connection_error(self, s3_client, caplog):
        # Patch delete_object to return an endpoint connection error
        mock_boto_client = s3_client.client
        error = EndpointConnectionError(endpoint_url="endpoint")
        mock_boto_client.delete_object.side_effect = error

        bucket = "bucket"
        key = "key"
        s3_client.delete_object(bucket, key)

        assert mock_boto_client.delete_object.call_count == 1
        assert caplog.records[0].levelname == "ERROR"
        assert caplog.records[0].error == error
        assert caplog.records[0].s3_bucket == bucket
        assert caplog.records[0].s3_key == key
Esempio n. 16
0
def test_default_aws_retry():
    # AssertionError should not retry
    e = AssertionError()
    assert not default_aws_retry(e)

    # NotImplementedError should not retry
    e = NotImplementedError()
    assert not default_aws_retry(e)

    # KeyError should not retry
    e = KeyError()
    assert not default_aws_retry(e)

    # IndexError should not retry
    e = IndexError()
    assert not default_aws_retry(e)

    # EndpointConnectionError should retry
    e = EndpointConnectionError(endpoint_url=None, error=None)
    assert default_aws_retry(e)

    # ConnectionClosedError should retry
    e = ConnectionClosedError(endpoint_url=None)
    assert default_aws_retry(e)

    # Generic BotoCoreError should not retry
    e = BotoCoreError()
    assert not default_aws_retry(e)

    # Generic ClientError should not retry
    err = {
        "Error": {
            "Code": "xxx",
            "Message": "xxx"
        }
    }
    e = ClientError(error_response=err, operation_name="xxx")
    assert not default_aws_retry(e)

    # ClientError with RequestLimitExceeded should retry
    err = {
        "Error": {
            "Code": "RequestLimitExceeded",
            "Message": "xxx"
        }
    }
    e = ClientError(error_response=err, operation_name="xxx")
    assert default_aws_retry(e)
Esempio n. 17
0
 def test_create_retry_handler_with_socket_errors(self):
     handler = retryhandler.create_retry_handler(
         self.retry_config, operation_name='OperationBar')
     exception = EndpointConnectionError(endpoint_url='')
     with self.assertRaises(EndpointConnectionError):
         handler(response=None, attempts=10,
                 caught_exception=exception)
     # No connection error raised because attempts < max_attempts.
     sleep_time = handler(response=None, attempts=1,
                          caught_exception=exception)
     self.assertEqual(sleep_time, 1)
     # But any other exception should be raised even if
     # attempts < max_attempts.
     with self.assertRaises(ValueError):
         sleep_time = handler(response=None, attempts=1,
                             caught_exception=ValueError())
Esempio n. 18
0
 async def _get_response(self, request, operation_model, attempts):
     # This will return a tuple of (success_response, exception)
     # and success_response is itself a tuple of
     # (http_response, parsed_dict).
     # If an exception occurs then the success_response is None.
     # If no exception occurs then exception is None.
     try:
         logger.debug("Sending http request: %s", request)
         headers = dict(self._headers(request.headers))
         http_response = await self.http_session.request(
             method=request.method,
             url=request.url,
             data=request.body,
             headers=headers,
             stream=True,
             verify=self.verify)
     except ConnectionError as e:
         # For a connection error, if it looks like it's a DNS
         # lookup issue, 99% of the time this is due to a misconfigured
         # region/endpoint so we'll raise a more specific error message
         # to help users.
         logger.debug("ConnectionError received when sending HTTP request.",
                      exc_info=True)
         if self._looks_like_dns_error(e):
             endpoint_url = e.request.url
             better_exception = EndpointConnectionError(
                 endpoint_url=endpoint_url, error=e)
             return (None, better_exception)
         elif self._looks_like_bad_status_line(e):
             better_exception = ConnectionClosedError(
                 endpoint_url=e.request.url, request=e.request)
             return (None, better_exception)
         else:
             return (None, e)
     except Exception as e:
         logger.debug("Exception received when sending HTTP request.",
                      exc_info=True)
         return (None, e)
     # This returns the http_response and the parsed_data.
     response_dict = await convert_to_response_dict(http_response,
                                                    operation_model)
     parser = self._response_parser_factory.create_parser(
         operation_model.metadata['protocol'])
     return ((http_response,
              parser.parse(response_dict,
                           operation_model.output_shape)), None)
    def test_create_document(
        self,
        mock_render_to_string,
        mock_write,
        mock_get_duties,
        mock_get_section_details,
        context,
        force,
        expected_template,
        expected_document_xml,
        expected_change,
        raise_write_exception,
    ):
        fake_file_name = 'fake_file.txt'

        mock_get_duties.return_value = None
        mock_get_section_details.return_value = None
        mock_write.return_value = fake_file_name
        if raise_write_exception:
            mock_write.side_effect = EndpointConnectionError(endpoint_url='')

        mock_render_to_string.return_value = expected_document_xml
        application = Application(CLASSIFICATION, force=force)
        db_chapter = ChapterFactory(id=1, description='Test')
        chapter = ClassificationChapter(application, db_chapter)
        chapter.create_document(context)

        if expected_document_xml:
            mock_render_to_string.assert_called_with(expected_template,
                                                     context)
            mock_write.asssert_called_with(expected_document_xml)
        else:
            assert mock_render_to_string.called is False
            assert mock_write.called is False

        if expected_change:
            document_history = ChapterDocumentHistory.objects.get(
                chapter=db_chapter)
            assert document_history.forced is force
            assert document_history.data == context
            assert document_history.change == expected_change
            assert document_history.remote_file_name == fake_file_name
        else:
            assert ChapterDocumentHistory.objects.filter(
                chapter=db_chapter).exists() is False
def test_create_document(
    mock_render_to_string,
    mock_write,
    context,
    force,
    expected_template,
    expected_document_xml,
    expected_change,
    raise_write_exception,
):
    fake_file_name = 'fake_file.txt'

    mock_write.return_value = fake_file_name
    if raise_write_exception:
        mock_write.side_effect = EndpointConnectionError(endpoint_url='')

    mock_render_to_string.return_value = expected_document_xml
    agreement = AgreementFactory(country_name='Espana',
                                 slug='spain',
                                 country_codes=['1011'])
    application = Application(country_profile='spain',
                              force_document_generation=force)
    document = Document(application)
    document.create_document(context)

    if expected_document_xml:
        mock_render_to_string.assert_called_with(expected_template, context)
        mock_write.asssert_called_with(expected_document_xml)
    else:
        assert mock_render_to_string.called is False
        assert mock_write.called is False

    if expected_change:
        document_history = AgreementDocumentHistory.objects.get(
            agreement=agreement)
        assert document_history.forced is force
        assert document_history.data == context
        assert document_history.change == expected_change
        assert document_history.remote_file_name == fake_file_name
    else:
        assert AgreementDocumentHistory.objects.filter(
            agreement=agreement).exists() is False
Esempio n. 21
0
    def test_check_if_key_exists__connection_problem(self):

        self.mocker.patch.object(self.s3.client, 'get_object').side_effect = [
            ClientError(
                operation_name='GET_OBJECT',
                error_response={'ResponseMetadata': {
                    'HTTPStatusCode': 403
                }}),
            EndpointConnectionError(endpoint_url='/some/url'),
        ]

        with pytest.raises(click.ClickException) as e:
            self.s3.check_if_key_exists('index.html')

        assert e.value.message == 'faced problems when connecting to AWS S3'

        with pytest.raises(click.ClickException) as e:
            self.s3.check_if_key_exists('index.html')

        assert e.value.message == 'could not connect to bucket specified'
Esempio n. 22
0
    def test_is_valid__client_or_connection_problem(self):

        self.mocker.patch.object(
            self.s3.client, 'list_objects').side_effect = [
                ClientError(operation_name='list_objects',
                            error_response={
                                'ResponseMetadata': {
                                    'HTTPStatusCode': 500
                                }
                            }),
                EndpointConnectionError(endpoint_url='/some/url'),
            ]

        with pytest.raises(click.ClickException) as e:
            self.s3.is_valid()

        assert e.value.message == 'faced problems when connecting to AWS S3'

        with pytest.raises(click.ClickException) as e:
            self.s3.is_valid()

        assert e.value.message == 'could not connect to the bucket specified'
Esempio n. 23
0
    def _get_response(self, request, operation_model, attempts):
        # This will return a tuple of (success_response, exception)
        # and success_response is itself a tuple of
        # (http_response, parsed_dict).
        # If an exception occurs then the success_response is None.
        # If no exception occurs then exception is None.
        try:
            # http request substituted too async one
            resp = yield from self._request(request.method, request.url,
                                            request.headers, request.body)
            http_response = resp

        except ConnectionError as e:
            # For a connection error, if it looks like it's a DNS
            # lookup issue, 99% of the time this is due to a misconfigured
            # region/endpoint so we'll raise a more specific error message
            # to help users.
            if self._looks_like_dns_error(e):
                endpoint_url = request.url
                better_exception = EndpointConnectionError(
                    endpoint_url=endpoint_url, error=e)
                return (None, better_exception)
            else:
                return (None, e)
        except Exception as e:
            # logger.debug("Exception received when sending HTTP request.",
            #              exc_info=True)
            return (None, e)

        # This returns the http_response and the parsed_data.
        response_dict = yield from convert_to_response_dict(
            http_response, operation_model)
        parser = self._response_parser_factory.create_parser(
            operation_model.metadata['protocol'])
        return ((http_response,
                 parser.parse(response_dict,
                              operation_model.output_shape)), None)
Esempio n. 24
0
def test_upload_file_simulating_endpointconnectionerror(tmp_dir_fixture):  # NOQA
    """
    Mock scenario where upload fails with a EndpointConnectionError exception.
    """

    from dtool_s3.storagebroker import _upload_file  # NOQA
    import boto3
    from botocore.exceptions import EndpointConnectionError

    s3client = boto3.client("s3")
    s3client.upload_file = MagicMock(
        side_effect=EndpointConnectionError(
            endpoint_url="dummy_bucket/dest_path")
    )

    value = _upload_file(
        s3client,
        "dummy_fpath",
        "dummy_bucket",
        "dummy_dest_path",
        "dummy_extra_args",
    )

    assert value is False
Esempio n. 25
0
 def mock_api_call(self, operation_name, api_params):
     assert operation_name == 'HeadBucket'
     if api_params['Bucket'] == 'private':
         raise EndpointConnectionError(endpoint_url='http://s3.example.com')
     return {}
Esempio n. 26
0
 def conn_err():
     raise EndpointConnectionError(endpoint_url='myurl')
Esempio n. 27
0
 def se_get():
     raise EndpointConnectionError(endpoint_url='myurl')
Esempio n. 28
0
    def send(self, request):
        try:
            proxy_url = self._proxy_config.proxy_url_for(request.url)
            manager = self._get_connection_manager(request.url, proxy_url)
            conn = manager.connection_from_url(request.url)
            self._setup_ssl_cert(conn, request.url, self._verify)
            if ensure_boolean(
                    os.environ.get('BOTO_EXPERIMENTAL__ADD_PROXY_HOST_HEADER',
                                   '')):
                # This is currently an "experimental" feature which provides
                # no guarantees of backwards compatibility. It may be subject
                # to change or removal in any patch version. Anyone opting in
                # to this feature should strictly pin botocore.
                host = urlparse(request.url).hostname
                conn.proxy_headers['host'] = host

            request_target = self._get_request_target(request.url, proxy_url)
            urllib_response = conn.urlopen(
                method=request.method,
                url=request_target,
                body=request.body,
                headers=request.headers,
                retries=Retry(False),
                assert_same_host=False,
                preload_content=False,
                decode_content=False,
                chunked=self._chunked(request.headers),
            )

            http_response = botocore.awsrequest.AWSResponse(
                request.url,
                urllib_response.status,
                urllib_response.headers,
                urllib_response,
            )

            if not request.stream_output:
                # Cause the raw stream to be exhausted immediately. We do it
                # this way instead of using preload_content because
                # preload_content will never buffer chunked responses
                http_response.content

            return http_response
        except URLLib3SSLError as e:
            raise SSLError(endpoint_url=request.url, error=e)
        except (NewConnectionError, socket.gaierror) as e:
            raise EndpointConnectionError(endpoint_url=request.url, error=e)
        except ProxyError as e:
            raise ProxyConnectionError(proxy_url=proxy_url, error=e)
        except URLLib3ConnectTimeoutError as e:
            raise ConnectTimeoutError(endpoint_url=request.url, error=e)
        except URLLib3ReadTimeoutError as e:
            raise ReadTimeoutError(endpoint_url=request.url, error=e)
        except ProtocolError as e:
            raise ConnectionClosedError(error=e,
                                        request=request,
                                        endpoint_url=request.url)
        except Exception as e:
            message = 'Exception received when sending urllib3 HTTP request'
            logger.debug(message, exc_info=True)
            raise HTTPClientError(error=e)
 def get_queue_by_name(self, **kwargs):
     raise EndpointConnectionError(endpoint_url='')
Esempio n. 30
0
    def _get_response(self, request, operation_model, attempts):
        # This will return a tuple of (success_response, exception)
        # and success_response is itself a tuple of
        # (http_response, parsed_dict).
        # If an exception occurs then the success_response is None.
        # If no exception occurs then exception is None.
        try:
            logger.debug("Sending http request: %s", request)
            history_recorder.record(
                'HTTP_REQUEST', {
                    'method': request.method,
                    'headers': request.headers,
                    'streaming': operation_model.has_streaming_input,
                    'url': request.url,
                    'body': request.body
                })
            http_response = self.http_session.send(
                request,
                verify=self.verify,
                stream=operation_model.has_streaming_output,
                proxies=self.proxies,
                timeout=self.timeout)
        except ConnectionError as e:
            # For a connection error, if it looks like it's a DNS
            # lookup issue, 99% of the time this is due to a misconfigured
            # region/endpoint so we'll raise a more specific error message
            # to help users.
            logger.debug("ConnectionError received when sending HTTP request.",
                         exc_info=True)
            if self._looks_like_dns_error(e):
                endpoint_url = e.request.url
                better_exception = EndpointConnectionError(
                    endpoint_url=endpoint_url, error=e)
                return (None, better_exception)
            elif self._looks_like_bad_status_line(e):
                better_exception = ConnectionClosedError(
                    endpoint_url=e.request.url, request=e.request)
                return (None, better_exception)
            else:
                return (None, e)
        except Exception as e:
            logger.debug("Exception received when sending HTTP request.",
                         exc_info=True)
            return (None, e)
        # This returns the http_response and the parsed_data.
        response_dict = convert_to_response_dict(http_response,
                                                 operation_model)

        http_response_record_dict = response_dict.copy()
        http_response_record_dict['streaming'] = \
            operation_model.has_streaming_output
        history_recorder.record('HTTP_RESPONSE', http_response_record_dict)

        if http_response.status_code == 200 and 'callback' in operation_model.metadata:
            parser = self._response_parser_factory.create_parser("rest-json")
            operation_model.metadata['protocol'] = "rest-json"
        else:
            parser = self._response_parser_factory.create_parser(
                operation_model.metadata['protocol'])
        parsed_response = parser.parse(response_dict,
                                       operation_model.output_shape)
        history_recorder.record('PARSED_RESPONSE', parsed_response)
        return (http_response, parsed_response), None