# How to connect to ECE with python?

**URL:** <https://discuss.elastic.co/t/how-to-connect-to-ece-with-python/88978>\
**Category:** Elastic Cloud Enterprise (ECE)\
**Created:** [June 12, 2017, 6:52am UTC](https://discuss.elastic.co/t/how-to-connect-to-ece-with-python/88978 "2017-06-12T06:52:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![weibin.wu](https://avatars.discourse-cdn.com/v4/letter/w/4491bb/32.png) [@weibin.wu](https://discuss.elastic.co/u/weibin.wu)\
**Post date:** [June 12, 2017, 6:52am UTC](https://discuss.elastic.co/t/how-to-connect-to-ece-with-python/88978/1 "2017-06-12T06:52:00Z")

</div>

Hi

I already whitelist 9243 port to my load test server.  
I can do with the following curl  
curl -XGET -k [https://user:password@3be9c7613c08413e8bc755802b107e6a.172.31.63.51.ip.es.io:9243](https://user:password@3be9c7613c08413e8bc755802b107e6a.172.31.63.51.ip.es.io:9243)

But when I was using python to connect. I download the cert from Cloud UI-\>platform-\>Settings and saved as "cloud\_certs"  
Then use the following code to connect.

es = Elasticsearch(  
["[https://3be9c7613c08413e8bc755802b107e6a.172.31.63.51.ip.es.io](https://3be9c7613c08413e8bc755802b107e6a.172.31.63.51.ip.es.io)"],  
port=9243,  
http\_auth="user:password",  
use\_ssl=True,  
verify\_certs=True,  
ca\_certs='cloud\_certs'  
)

It gives me

elasticsearch.exceptions.ConnectionError: ConnectionError((\<urllib3.connection.VerifiedHTTPSConnection object at 0x7f862617b990\>, 'Connection to [3be9c7613c08413e8bc755802b107e6a.172.31.63.51.ip.es.io](http://3be9c7613c08413e8bc755802b107e6a.172.31.63.51.ip.es.io) timed out. (connect timeout=10)')) caused by: ConnectTimeoutError((\<urllib3.connection.VerifiedHTTPSConnection object at 0x7f862617b990\>, 'Connection to [3be9c7613c08413e8bc755802b107e6a.172.31.63.51.ip.es.io](http://3be9c7613c08413e8bc755802b107e6a.172.31.63.51.ip.es.io) timed out. (connect timeout=10)'))

I tried a lot of trouble shoot but no good news. Whats the correct way to use pythong connect to ECE?

---

<div class="post-metadata">

**Author:** ![uricohen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/uricohen/32/9776_2.png) [@uricohen](https://discuss.elastic.co/u/uricohen)\
**Post date:** [June 12, 2017, 11:43am UTC](https://discuss.elastic.co/t/how-to-connect-to-ece-with-python/88978/2 "2017-06-12T11:43:49Z")

</div>

Hi @weibin.wu

Note that the hostname you're using ends with `172.31.63.51.ip.es.io`. The `ip.es.io` domain is a "magic" domain name managed by Elastic, that provides wildcard DNS for any IP address. So in your case, `172.31.63.51.ip.es.io` will simply resolve to `172.31.63.51`. We use this solution to save the need for users to define their own wildcard DNS record while evaluating ECE. In a production setup, you probably don't want to rely on this service, and we recommend that you have your own wildcard DNS name that resolves to one of the ECE proxy hosts or a load balancer that fronts them.  
In this specific case, for this to work properly you need to make sure that:

- The host which runs your Python code has internet access (so it can access `ip.es.io`).
- The IP adderss `172.31.63.51` resolves from that same host.

HTH  
Uri

---

<div class="post-metadata">

**Author:** ![Alex\_Piggott](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_piggott/32/11053_2.png) [@Alex\_Piggott](https://discuss.elastic.co/u/Alex_Piggott)\
**Post date:** [June 12, 2017, 12:36pm UTC](https://discuss.elastic.co/t/how-to-connect-to-ece-with-python/88978/3 "2017-06-12T12:36:07Z")

</div>

Hi @weibin.wu

Can you try connecting over `:9200` first? Eg open `:9200` in the firewall and connect to `http://3be9c7613c08413e8bc755802b107e6a.172.31.63.51.ip.es.io:9200` first via `curl` and then with a similar python snippet.

That will take certification issues out the way, and also importantly, if the connection to 9200 fails you can use `tcpdump` to diagnose what's going on.

(You might also be able to get more information by upping the logging level:

```auto
import logging
logging.basicConfig(level=logging.DEBUG)

```

)

Alex

---

<div class="post-metadata">

**Author:** ![weibin.wu](https://avatars.discourse-cdn.com/v4/letter/w/4491bb/32.png) [@weibin.wu](https://discuss.elastic.co/u/weibin.wu)\
**Post date:** [June 13, 2017, 2:45am UTC](https://discuss.elastic.co/t/how-to-connect-to-ece-with-python/88978/4 "2017-06-13T02:45:22Z")

</div>

> [@uricohen](#):
>
> [ip.es.io](http://ip.es.io)

Thats an very impressing DNS magic. Thanks

I checked our server has internet access and can resolve the [ip.es.io](http://ip.es.io).  
Do you have an example of code to connect to ECE with python?

---

<div class="post-metadata">

**Author:** ![weibin.wu](https://avatars.discourse-cdn.com/v4/letter/w/4491bb/32.png) [@weibin.wu](https://discuss.elastic.co/u/weibin.wu)\
**Post date:** [June 13, 2017, 2:48am UTC](https://discuss.elastic.co/t/how-to-connect-to-ece-with-python/88978/5 "2017-06-13T02:48:40Z")

</div>

Thanks Alex,

That really resolve my problem. Becuase we are using ECE as an internal service. So using port 9200 will facilitate a lot for our work rather than using port 9243.

---

<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:** [June 27, 2017, 2:49am UTC](https://discuss.elastic.co/t/how-to-connect-to-ece-with-python/88978/6 "2017-06-27T02:49:32Z")

</div>

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