Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES/12136.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
``ClientConnectorCertificateError.os_error`` no longer raises :exc:`AttributeError`
-- by :user:`themylogin`.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ Vladimir Kamarzin
Vladimir Kozlovski
Vladimir Rutsky
Vladimir Shulyak
Vladimir Vinogradenko
Vladimir Zakharov
Vladyslav Bohaichuk
Vladyslav Bondar
Expand Down
15 changes: 13 additions & 2 deletions aiohttp/client_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,21 @@ class ClientConnectorSSLError(*ssl_error_bases): # type: ignore[misc]
class ClientConnectorCertificateError(*cert_errors_bases): # type: ignore[misc]
"""Response certificate error."""

_conn_key: ConnectionKey

def __init__(
self, connection_key: ConnectionKey, certificate_error: Exception
# TODO: If we require ssl in future, this can become ssl.CertificateError
self,
connection_key: ConnectionKey,
certificate_error: Exception,
) -> None:
self._conn_key = connection_key
if isinstance(certificate_error, cert_errors + (OSError,)):
# ssl.CertificateError has errno and strerror, so we should be fine
os_error = certificate_error
else:
os_error = OSError()

super().__init__(connection_key, os_error)
self._certificate_error = certificate_error
self.args = (connection_key, certificate_error)

Expand Down
9 changes: 9 additions & 0 deletions tests/test_client_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,15 @@ def test_str(self) -> None:
" [Exception: ('Bad certificate',)]"
)

def test_oserror(self) -> None:
certificate_error = OSError(1, "Bad certificate")
err = client.ClientConnectorCertificateError(
connection_key=self.connection_key, certificate_error=certificate_error
)
assert err.os_error == certificate_error
assert err.errno == 1
assert err.strerror == "Bad certificate"


class TestServerDisconnectedError:
def test_ctor(self) -> None:
Expand Down
Loading