# \[elasticsearch-py\] problem with connection

**URL:** <https://discuss.elastic.co/t/elasticsearch-py-problem-with-connection/79824>\
**Category:** Elasticsearch\
**Created:** [March 24, 2017, 1:44am UTC](https://discuss.elastic.co/t/elasticsearch-py-problem-with-connection/79824 "2017-03-24T01:44:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [March 24, 2017, 1:44am UTC](https://discuss.elastic.co/t/elasticsearch-py-problem-with-connection/79824/1 "2017-03-24T01:44:32Z")

</div>

Hi,  
We're using elastic py from elastic 0.9 and we recently migrate to 5.2  
We used to create a connection this way:  
`elasticsearch_server = ('127.0.0.1:9200') es = elasticsearch.Elasticsearch(elasticsearch_server, timeout=10, retry_on_timeout=True, sniff_on_start=False, sniff_on_connection_fail=True, sniff_timeout=10, serializer=JSONSerializerPython2(), sniffer_timeout=30)`

Everything is working correctly until I add a new server that doesn't yet exist.

`elasticsearch_server = ('127.0.0.1:9200') ---> elasticsearch_server = ('127.0.0.1:9200', '1.2.3.4:9200')`

Then it raise a TransportError: TransportError(N/A, 'Unable to sniff hosts - no viable hosts found.')  
If I remove the 1234 ip I can connect without problem.

What wrong? if I have 2 serves and I lost one, I can no more run with only one server???

This one was working perfectly with previous version so maybe because of new option?  
I checked the doc but found nothing!

If somebody have a tip.

And another things: If I set sniff\_on\_start=True it raise a TransportError

I return debugging!

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [March 24, 2017, 2:20am UTC](https://discuss.elastic.co/t/elasticsearch-py-problem-with-connection/79824/2 "2017-03-24T02:20:31Z")

</div>

Here more information:

I put some debug in [transport.py/sniff\_hosts()](http://transport.py/sniff_hosts())

Here the list of the host sniffed which is correct (1234 Ip doesn't exist):  
`[{u'transport_address': u'127.0.0.1:9300', u'name': u'banana-node-1', u'roles': [u'master', u'data', u'ingest'], u'ip': u'127.0.0.1', u'host': u'127.0.0.1', u'version': u'5.2.2', u'build_hash': u'f9d9b74'}]`

But after in the code he try to read the IP with the following key: "http\_address"

And this key is not in the dict so it return a list of empty hosts??!!!! 😢

Something wrong with my configuration need to set somewhere the transport protocol?

Dive back in the doc and debug.

========================= EDIT ======================

I figure out that the elasticsearch lib was not up to date 😞  
So I upgrade to the last version 5.2 (previously 5.0.1)

But my problem is still not solved, I set the timeout to 2 sec.

If the 2 servers are on, no problem, but If I switch off one, on each request I have a latency (~\> timeout) and in my log this error:

```
ConnectTimeoutError: (<urllib3.connection.HTTPConnection object at 0x7f515c575390>, u'Connection to 172.16.40.151 timed out. (connect timeout=2)')
WARNING:elasticsearch:Connection <Urllib3HttpConnection: http://172.16.40.151:9200> has failed for 1 times in a row, putting on 60 second timeout.
```

---

<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:** [April 21, 2017, 2:20am UTC](https://discuss.elastic.co/t/elasticsearch-py-problem-with-connection/79824/3 "2017-04-21T02:20:43Z")

</div>

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