# Connection error when using a domain in python client to connect the elasticsearch

**URL:** https://discuss.elastic.co/t/connection-error-when-using-a-domain-in-python-client-to-connect-the-elasticsearch/244650
**Category:** Elasticsearch
**Created:** [August 12, 2020, 2:59am UTC](https://discuss.elastic.co/t/connection-error-when-using-a-domain-in-python-client-to-connect-the-elasticsearch/244650 "2020-08-12T02:59:32Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Tristan\_D](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tristan_d/32/73492_2.png) [@Tristan\_D](https://discuss.elastic.co/u/Tristan_D)
#### Post date: [August 12, 2020, 2:59am UTC](https://discuss.elastic.co/t/connection-error-when-using-a-domain-in-python-client-to-connect-the-elasticsearch/244650/1 "2020-08-12T02:59:32Z")

</div>

I can't connect to the es with the direct ip:9200, so I use a domain. The domain is mapping to es\_ip:9200.  
It's fine when I use curl command to test the connection.  
`curl ai-xiaov-async.vivo.com.cn/_cat/indices`  
But in Python, I can't connect to the es with this domain, it get a connection error.

The code in Python

```auto
from elasticsearch import Elasticsearch
class ElasticsearchViewset(viewsets.ViewSet):
    @action(methods=['GET'], detail=False, permission_classes=[AllowAny])
    def get_log(self, request):
        es = Elasticsearch(['ai-xiaov-async.vivo.com.cn'])
        result = es.info()
        return Response(result)

```

The error imformation

```auto
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x00000249EF3FEE80>: Failed to establish a new connection: [WinError 10061]

elasticsearch.exceptions.ConnectionError: ConnectionError(<urllib3.connection.HTTPConnection object at 0x00000249EF3FEE80>: Failed to establish a new connection: [WinError 10061]

```

Can I use a domain to connect the es?

---

<div class="post-metadata">

### Author: ![Tristan\_D](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tristan_d/32/73492_2.png) [@Tristan\_D](https://discuss.elastic.co/u/Tristan_D)
#### Post date: [August 12, 2020, 7:08am UTC](https://discuss.elastic.co/t/connection-error-when-using-a-domain-in-python-client-to-connect-the-elasticsearch/244650/2 "2020-08-12T07:08:30Z")

</div>

It's sovled.  
I added the port in the connection  
`es = Elasticsearch(['ai-xiaov-async.vivo.com.cn:80'])`

---

<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: [September 9, 2020, 7:08am UTC](https://discuss.elastic.co/t/connection-error-when-using-a-domain-in-python-client-to-connect-the-elasticsearch/244650/3 "2020-09-09T07:08:36Z")

</div>

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