# Elasticsearch-py urllib3 suppress traceback logs on connection failures

**URL:** <https://discuss.elastic.co/t/elasticsearch-py-urllib3-suppress-traceback-logs-on-connection-failures/276561>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [June 21, 2021, 3:49pm UTC](https://discuss.elastic.co/t/elasticsearch-py-urllib3-suppress-traceback-logs-on-connection-failures/276561 "2021-06-21T15:49:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jratliff](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jratliff/32/52746_2.png) [@jratliff](https://discuss.elastic.co/u/jratliff)\
**Post date:** [June 21, 2021, 3:49pm UTC](https://discuss.elastic.co/t/elasticsearch-py-urllib3-suppress-traceback-logs-on-connection-failures/276561/1 "2021-06-21T15:49:00Z")

</div>

```auto
        client = Elasticsearch(
            hosts=config['hosts'],
            http_auth=(config['auth']['user'], config['auth']['password']),
            scheme='https',
            ssl_context=context,
            timeout=3600,
        )

        if not client.ping():
            logger.error(
                FmtStr('Unable to connect to Elasticsearch {}', config['hosts'])
            )
            return None

```

If the client cannot connect to the Elasticsearch server, I get half a dozen tracebacks in urllib3.

```auto
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 170, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 96, in create_connection
    raise err
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 86, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/elasticsearch/connection/http_urllib3.py", line 252, in perform_request
    method, url, body, retries=Retry(False), headers=request_headers, **kw
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 756, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/retry.py", line 507, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/local/lib/python3.6/site-packages/urllib3/packages/six.py", line 770, in reraise
    raise value
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 706, in urlopen
    chunked=chunked,
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 382, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 1010, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 353, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 182, in _new_conn
    self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7f242a46eb38>: Failed to establish a new connection: [Errno 111] Connection refused
2021-06-21 15:36:14 WARNING (elasticsearch): HEAD https://netflow-frontend.bldc.nwave.noaa.gov:9200/ [status:N/A request:0.003s]
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 170, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 96, in create_connection
    raise err
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 86, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/elasticsearch/connection/http_urllib3.py", line 252, in perform_request
    method, url, body, retries=Retry(False), headers=request_headers, **kw
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 756, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/retry.py", line 507, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/local/lib/python3.6/site-packages/urllib3/packages/six.py", line 770, in reraise
    raise value
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 706, in urlopen
    chunked=chunked,
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 382, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 1010, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 353, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 182, in _new_conn
    self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7f242a46ed68>: Failed to establish a new connection: [Errno 111] Connection refused

```

I've tried catching every exception, or even just Error or Exception, but none of it is caught and nothing prevents the extra log garbage.

Is there something I can do to suppress these tracebacks?

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 19, 2021, 3:49pm UTC](https://discuss.elastic.co/t/elasticsearch-py-urllib3-suppress-traceback-logs-on-connection-failures/276561/2 "2021-07-19T15:49:41Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
