From 376a37568d1057342d0e216de5fa56e10e533941 Mon Sep 17 00:00:00 2001 From: Bryan Kok Date: Mon, 30 Sep 2019 16:49:34 +0800 Subject: [PATCH] Fix misleading message in the string representation of `ClientConnectorError` (#4097) --- CHANGES/4097.bugfix | 1 + aiohttp/client_exceptions.py | 5 +++-- tests/test_client_exceptions.py | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 CHANGES/4097.bugfix diff --git a/CHANGES/4097.bugfix b/CHANGES/4097.bugfix new file mode 100644 index 00000000000..af521a4e6fa --- /dev/null +++ b/CHANGES/4097.bugfix @@ -0,0 +1 @@ +Fix misleading message in the string representation of `ClientConnectorError`; `self.ssl == None` means certification checks relaxed, not SSL disabled diff --git a/aiohttp/client_exceptions.py b/aiohttp/client_exceptions.py index 5640b1b0d94..2738611b205 100644 --- a/aiohttp/client_exceptions.py +++ b/aiohttp/client_exceptions.py @@ -136,8 +136,9 @@ def ssl(self) -> Union[SSLContext, None, bool, 'Fingerprint']: return self._conn_key.ssl def __str__(self) -> str: - return ('Cannot connect to host {0.host}:{0.port} ssl:{0.ssl} [{1}]' - .format(self, self.strerror)) + return ('Cannot connect to host {0.host}:{0.port} ssl:{1} [{2}]' + .format(self, self.ssl if self.ssl is not None else 'default', + self.strerror)) # OSError.__reduce__ does too much black magick __reduce__ = BaseException.__reduce__ diff --git a/tests/test_client_exceptions.py b/tests/test_client_exceptions.py index 8cde84b3b2f..fee4cf4dcc5 100644 --- a/tests/test_client_exceptions.py +++ b/tests/test_client_exceptions.py @@ -123,8 +123,8 @@ def test_str(self) -> None: err = client.ClientConnectorError( connection_key=self.connection_key, os_error=OSError(errno.ENOENT, 'No such file')) - assert str(err) == ("Cannot connect to host example.com:8080 ssl:None " - "[No such file]") + assert str(err) == ("Cannot connect to host example.com:8080 ssl:" + "default [No such file]") class TestClientConnectorCertificateError: