Skip to content

Improve SSL error handling with specific exception types#1542

Merged
maurosoria merged 3 commits into
maurosoria:masterfrom
mohamedsolaiman:fix/ssl-error-handling
Apr 28, 2026
Merged

Improve SSL error handling with specific exception types#1542
maurosoria merged 3 commits into
maurosoria:masterfrom
mohamedsolaiman:fix/ssl-error-handling

Conversation

@mohamedsolaiman
Copy link
Copy Markdown
Contributor

Replace string-based SSL error detection with isinstance checks and provide specific actionable error messages. Closes #1444

mohamedsolaiman and others added 3 commits April 28, 2026 16:54
…soria#1444)

Replace fragile string-based SSL error detection with proper isinstance
checks and provide specific, actionable error messages instead of the
generic 'Unexpected SSL error' message.

Changes in Requester (sync):
- Replace '"SSLError" in str(e)' with isinstance checks using
  ssl.SSLError and detection of requests-wrapped SSL errors via
  exception chain inspection
- Use _format_ssl_error() for detailed error messages

Changes in AsyncRequester (async):
- Use _format_ssl_error() instead of generic 'Unexpected SSL error'

New helper functions:
- _is_requests_ssl_error(): Detects SSL errors wrapped by the
  requests library (requests.exceptions.SSLError) by walking the
  exception cause chain (PEP 3134)
- _format_ssl_error(): Provides specific error messages for common
  SSL errors:
  - Certificate verification failures (self-signed, expired,
    not yet valid, missing issuer, hostname mismatch)
  - SSL handshake failures
  - Protocol version mismatches
  - Cipher suite negotiation failures
  - Unexpected connection termination
  - Falls back to library/reason from ssl.SSLError attributes

Also adds proper warning-level logging for SSL errors with details
(library, reason, error detail) to aid debugging.

Closes: maurosoria#1444
@maurosoria maurosoria merged commit 5fd450a into maurosoria:master Apr 28, 2026
5 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected SSL error

2 participants