# How the python 2.6.8 to connect the Elasticsearch?

**URL:** <https://discuss.elastic.co/t/how-the-python-2-6-8-to-connect-the-elasticsearch/215561>\
**Category:** Elasticsearch\
**Created:** [January 18, 2020, 1:51pm UTC](https://discuss.elastic.co/t/how-the-python-2-6-8-to-connect-the-elasticsearch/215561 "2020-01-18T13:51:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunnut](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@sunnut](https://discuss.elastic.co/u/sunnut)\
**Post date:** [January 18, 2020, 1:51pm UTC](https://discuss.elastic.co/t/how-the-python-2-6-8-to-connect-the-elasticsearch/215561/1 "2020-01-18T13:51:05Z")

</div>

The python version is 2.6.8 that ssl has not create\_default\_context.

how can i skip the ssl or another method to tansport the ssl certificates besides above

---

<div class="post-metadata">

**Author:** ![rugenl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rugenl/32/12887_2.png) [@rugenl](https://discuss.elastic.co/u/rugenl)\
**Post date:** [January 18, 2020, 5:40pm UTC](https://discuss.elastic.co/t/how-the-python-2-6-8-to-connect-the-elasticsearch/215561/2 "2020-01-18T17:40:11Z")

</div>

Python 2 sunset date was 1/1/2020, not that it still won't work, but if I were doing new development, I'd use Python 3.

Did you do any imports?

Here is my sample code, I don't recall any differences between Python 2 and 3 in this section.

```
#!/bin/python3
from elasticsearch import *
from elasticsearch_dsl import *
from ssl import create_default_context
import getpass
context = create_default_context(cafile="es_ca.cer")
pw = getpass.getpass(prompt='Password for elastic stack')

#
# Get data from ES
#
es = Elasticsearch(["https://elastic.dns:9200"],http_auth=("user", pw), ssl_context=context)
aliases = es.indices.get_alias("*")
```

---

<div class="post-metadata">

**Author:** ![sunnut](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@sunnut](https://discuss.elastic.co/u/sunnut)\
**Post date:** [January 19, 2020, 12:26pm UTC](https://discuss.elastic.co/t/how-the-python-2-6-8-to-connect-the-elasticsearch/215561/3 "2020-01-19T12:26:45Z")

</div>

Thank you for your reply, the problem is fixed.

But meet another error as following:  
File "/opt/anaconda2/envs/py2/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 84, in \_wrapped  
return func(\*args, params=params, \*\*kwargs)  
File "/opt/anaconda2/envs/py2/lib/python2.7/site-packages/elasticsearch/client/indices.py", line 510, in get\_alias  
"GET", \_make\_path(index, "\_alias", name), params=params  
File "/opt/anaconda2/envs/py2/lib/python2.7/site-packages/elasticsearch/transport.py", line 358, in perform\_request  
timeout=timeout,  
File "/opt/anaconda2/envs/py2/lib/python2.7/site-packages/elasticsearch/connection/http\_urllib3.py", line 254, in perform\_request  
raise ConnectionError("N/A", str(e), e)  
elasticsearch.exceptions.ConnectionError: ConnectionError(check\_hostname requires server\_hostname) caused by: ValueError(check\_hostname requires server\_hostname)

---

<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:** [February 16, 2020, 12:26pm UTC](https://discuss.elastic.co/t/how-the-python-2-6-8-to-connect-the-elasticsearch/215561/4 "2020-02-16T12:26:52Z")

</div>

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