def _is_retryable_exception ( e ) : if isinstance ( e , urllib3 . exceptions . ProtocolError ) : e = e . args [ 1 ] if isinstance ( e , ( socket . gaierror , socket . herror ) ) : return True if isinstance ( e , socket . error ) and e . errno in _RETRYABLE_SOCKET_ERRORS : return True if isinstance ( e , urllib3 . exceptions . NewConnectionError ) : return True return False
how to check if a connection is refused in python
Returns True if the exception is always safe to retry .
def _is_retryable_exception(e):
    """Returns True if the exception is always safe to retry.

    This is True if the client was never able to establish a connection
    to the server (for example, name resolution failed or the connection
    could otherwise not be initialized).

    Conservatively, if we can't tell whether a network connection could
    have been established, we return False.

    """
    if isinstance(e, urllib3.exceptions.ProtocolError):
        e = e.args[1]
    if isinstance(e, (socket.gaierror, socket.herror)):
        return True
    if isinstance(e, socket.error) and e.errno in _RETRYABLE_SOCKET_ERRORS:
        return True
    if isinstance(e, urllib3.exceptions.NewConnectionError):
        return True
    return False