# \[Errno 111\] Connection refused)

**URL:** <https://discuss.elastic.co/t/errno-111-connection-refused/253813>\
**Category:** Elasticsearch\
**Created:** [October 30, 2020, 12:07pm UTC](https://discuss.elastic.co/t/errno-111-connection-refused/253813 "2020-10-30T12:07:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![subham\_p](https://avatars.discourse-cdn.com/v4/letter/s/71e660/32.png) [@subham\_p](https://discuss.elastic.co/u/subham_p)\
**Post date:** [October 30, 2020, 12:07pm UTC](https://discuss.elastic.co/t/errno-111-connection-refused/253813/1 "2020-10-30T12:07:59Z")

</div>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):  
File "for\_bulk\_insert.py", line 61, in   
es.indices.delete(index=index\_name, ignore=[400, 404])  
File "/home/subham/subhamenv/lib64/python3.6/site-packages/elasticsearch/client/utils.py", line 152, in \_wrapped  
return func(\*args, params=params, headers=headers, \*\*kwargs)  
File "/home/subham/subhamenv/lib64/python3.6/site-packages/elasticsearch/client/indices.py", line 286, in delete  
"DELETE", \_make\_path(index), params=params, headers=headers  
File "/home/subham/subhamenv/lib64/python3.6/site-packages/elasticsearch/transport.py", line 390, in perform\_request  
raise e  
File "/home/subham/subhamenv/lib64/python3.6/site-packages/elasticsearch/transport.py", line 365, in perform\_request  
timeout=timeout,  
File "/home/subham/subhamenv/lib64/python3.6/site-packages/elasticsearch/connection/http\_urllib3.py", line 258, in perform\_request  
raise ConnectionError("N/A", str(e), e)  
elasticsearch.exceptions.ConnectionError: ConnectionError(\<urllib3.connection.HTTPConnection object at 0x7f68bba86358\>: Failed to establish a new connection: [Errno 111] Connection refused) caused by: NewConnectionError(\<urllib3.connection.HTTPConnection object at 0x7f68bba86358\>: Failed to establish a new connection: [Errno 111] Connection refused)

---

<div class="post-metadata">

**Author:** ![xeraa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xeraa/32/48181_2.png) [@xeraa](https://discuss.elastic.co/u/xeraa)\
**Post date:** [November 1, 2020, 4:12pm UTC](https://discuss.elastic.co/t/errno-111-connection-refused/253813/2 "2020-11-01T16:12:36Z")

</div>

1. Please format your code as such for easier readability.
2. "During handling of the above exception, another exception occurred:" What is "above" and what is "another" here? Also adding the relevant code snippet might help to figure out the problem.

---

<div class="post-metadata">

**Author:** ![subham\_p](https://avatars.discourse-cdn.com/v4/letter/s/71e660/32.png) [@subham\_p](https://discuss.elastic.co/u/subham_p)\
**Post date:** [November 3, 2020, 1:18am UTC](https://discuss.elastic.co/t/errno-111-connection-refused/253813/3 "2020-11-03T01:18:22Z")

</div>

HIi.. DEar..

```auto
#importing Dictionary
import psycopg2
from elasticsearch import Elasticsearch
from elasticsearch import helpers
import datetime
import pandas as pd
from pandas import DataFrame

#Establishing the connection with ELK
es= Elasticsearch([' '], http_auth=(' ', ' '))

#es.cluster.health(wait_for_status='yellow', request_timeout=2)

#establishing the connection
conn = psycopg2.connect( database=' ', user=' ', password=' ', host=' ', port= ' ' )#configured database 

if conn:
    print ("Connected Successfully")
else:
    print ("Connection Not Established")

mydict = create_dict()
query="select * from emr.patient_summarized_test_data_trans Limit 1000" 
cursor = conn.cursor()
cursor.execute(query)
result = cursor.fetchall()
df = DataFrame(result,columns=["summarized_test_data_id","package_id","panel_id",
                            "test_id","loinc_nm","test_type","test_result","patient_id","hos_patient_id"])

json_str = df.to_json(orient='records')

json_records = json.loads(json_str)

es = Elasticsearch()
index_name = 'in-dev-patient-summary-research6'
doctype = 'summary-research6'
es.indices.delete(index=index_name, ignore=[400, 404])
es.indices.create(index=index_name, ignore=400)
action_list = []
for row in json_records:
    record ={
        '_op_type': 'index',
        '_index': index_name,
        '_type' : doctype,
        '_source': row
    }
    action_list.append(record)
helpers.bulk(es, action_list,request_timeout=3600)

```

Output;  
File "/home/subham/subhamenv/lib64/python3.6/site-packages/elasticsearch/connection/http\_urllib3.py", line 258, in perform\_request  
raise ConnectionError("N/A", str(e), e)  
elasticsearch.exceptions.ConnectionError: ConnectionError(\<urllib3.connection.HTTPConnection object at 0x7f68bba86358\>: Failed to establish a new connection: [Errno 111] Connection refused) caused by: NewConnectionError(\<urllib3.connection.HTTPConnection object at 0x7f68bba86358\>: Failed to establish a new connection: [Errno 111] Connection refused)

---

<div class="post-metadata">

**Author:** ![xeraa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xeraa/32/48181_2.png) [@xeraa](https://discuss.elastic.co/u/xeraa)\
**Post date:** [November 3, 2020, 1:25am UTC](https://discuss.elastic.co/t/errno-111-connection-refused/253813/4 "2020-11-03T01:25:35Z")

</div>

What happens if you try a cURL request (`curl -u <user>:<password> <host>`) from the machine where you are running the Python code against Elasticsearch? This looks like a connection problem — wrong port, firewall, Elasticsearch not bound to the interface you're trying to access,...

---

<div class="post-metadata">

**Author:** ![subham\_p](https://avatars.discourse-cdn.com/v4/letter/s/71e660/32.png) [@subham\_p](https://discuss.elastic.co/u/subham_p)\
**Post date:** [November 3, 2020, 6:00am UTC](https://discuss.elastic.co/t/errno-111-connection-refused/253813/5 "2020-11-03T06:00:00Z")

</div>

Dear xeraa... I got this response

````auto
(subhamenv) [user@abc ~]$ `curl -u <user>:<password> <host>`
{
  "name" : "elk.abc.care",
  "cluster_name" : "elk-dev",
  "cluster_uuid" : "DUUGqBupTmyBar4fN4-tiQ",
  "version" : {
    "number" : "7.9.1",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "083627f112ba94dffc1232e8b42b73492789ef91",
    "build_date" : "2020-09-01T21:22:21.964974Z",
    "build_snapshot" : false,
    "lucene_version" : "8.6.2",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}```
````

---

<div class="post-metadata">

**Author:** ![xeraa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xeraa/32/48181_2.png) [@xeraa](https://discuss.elastic.co/u/xeraa)\
**Post date:** [November 7, 2020, 7:27pm UTC](https://discuss.elastic.co/t/errno-111-connection-refused/253813/6 "2020-11-07T19:27:26Z")

</div>

That looks good. Can you try a minimal connection example (with security enabled): [https://elasticsearch-py.readthedocs.io/en/7.9.1/#ssl-and-authentication](https://elasticsearch-py.readthedocs.io/en/7.9.1/#ssl-and-authentication)?

Not sure if you have set up TLS, but maybe you are missing `scheme="https"`?

---

<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:** [December 5, 2020, 7:27pm UTC](https://discuss.elastic.co/t/errno-111-connection-refused/253813/7 "2020-12-05T19:27:27Z")

</div>

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