Skip to content

Conversation

@amritamishra01
Copy link

Summary

This PR improves the developer experience by providing more actionable and human-readable error messages for common connection failures, resolving #6722.

Currently, connection errors are often wrapped in a generic ConnectionError with a complex traceback that can be confusing for beginners. This change inspects the underlying exception to identify specific issues like DNS failures, refused connections, and unreachable networks.

Changes

  • Modified HTTPAdapter.send in requests/adapters.py to inspect NewConnectionError and MaxRetryError.
  • Added specific logic to detect and label:
    • DNS Failures (socket.gaierror): "Name resolution failed..."
    • Connection Refused (ConnectionRefusedError): "Connection refused by..."
    • Network Unreachable (OSError with errno 101/10051): "Network unreachable..."
  • Preserved the original traceback using raise ... from e so advanced debugging context is not lost.

Verification

I verified these changes locally using a reproduction script that simulates:

  1. A non-existent domain (DNS error).
  2. A connection to a closed local port (Connection Refused).
  3. A connection with a tiny timeout/unreachable network (Timeout/Unreachable).

All scenarios now output the enhanced, friendly error messages while maintaining the original exception chain.

@sigmavirus24
Copy link
Contributor

The original issue was not sufficiently specified and hasn't responded to questions in two years. This is LLM slop without any test coverage, so we won't be accepting it

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.

2 participants