Skip to content

Commit 24e32f6

Browse files
themyloginpatchback[bot]
authored andcommitted
Fix AttributeError: 'ClientConnectorCertificateError' object has no attribute '_os_error'. (#12136)
(cherry picked from commit c0f1513)
1 parent 08c6270 commit 24e32f6

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

CHANGES/12136.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``ClientConnectorCertificateError.os_error`` no longer raises :exc:`AttributeError`
2+
-- by :user:`themylogin`.

CONTRIBUTORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ Vladimir Kamarzin
382382
Vladimir Kozlovski
383383
Vladimir Rutsky
384384
Vladimir Shulyak
385+
Vladimir Vinogradenko
385386
Vladimir Zakharov
386387
Vladyslav Bohaichuk
387388
Vladyslav Bondar

aiohttp/client_exceptions.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,21 @@ class ClientConnectorSSLError(*ssl_error_bases): # type: ignore[misc]
380380
class ClientConnectorCertificateError(*cert_errors_bases): # type: ignore[misc]
381381
"""Response certificate error."""
382382

383+
_conn_key: ConnectionKey
384+
383385
def __init__(
384-
self, connection_key: ConnectionKey, certificate_error: Exception
386+
# TODO: If we require ssl in future, this can become ssl.CertificateError
387+
self,
388+
connection_key: ConnectionKey,
389+
certificate_error: Exception,
385390
) -> None:
386-
self._conn_key = connection_key
391+
if isinstance(certificate_error, cert_errors + (OSError,)):
392+
# ssl.CertificateError has errno and strerror, so we should be fine
393+
os_error = certificate_error
394+
else:
395+
os_error = OSError()
396+
397+
super().__init__(connection_key, os_error)
387398
self._certificate_error = certificate_error
388399
self.args = (connection_key, certificate_error)
389400

tests/test_client_exceptions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,15 @@ def test_str(self) -> None:
232232
" [Exception: ('Bad certificate',)]"
233233
)
234234

235+
def test_oserror(self) -> None:
236+
certificate_error = OSError(1, "Bad certificate")
237+
err = client.ClientConnectorCertificateError(
238+
connection_key=self.connection_key, certificate_error=certificate_error
239+
)
240+
assert err.os_error == certificate_error
241+
assert err.errno == 1
242+
assert err.strerror == "Bad certificate"
243+
235244

236245
class TestServerDisconnectedError:
237246
def test_ctor(self) -> None:

0 commit comments

Comments
 (0)