# \[SOLVED\] Python's ES Module: Getting Connection Refused on Local VM but not the Servers

**URL:** <https://discuss.elastic.co/t/solved-pythons-es-module-getting-connection-refused-on-local-vm-but-not-the-servers/28869>\
**Category:** Elasticsearch\
**Created:** [September 8, 2015, 9:01pm UTC](https://discuss.elastic.co/t/solved-pythons-es-module-getting-connection-refused-on-local-vm-but-not-the-servers/28869 "2015-09-08T21:01:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zylo47](https://avatars.discourse-cdn.com/v4/letter/z/5fc32e/32.png) [@zylo47](https://discuss.elastic.co/u/zylo47)\
**Post date:** [September 8, 2015, 9:01pm UTC](https://discuss.elastic.co/t/solved-pythons-es-module-getting-connection-refused-on-local-vm-but-not-the-servers/28869/1 "2015-09-08T21:01:02Z")

</div>

I am using the Elasticsearch Python module to develop some code to create and restore snapshots. I have been doing most of the initial coding by connecting to the servers but I need to do the rest on a local VM.

The servers are Centos 6.5 and my VM is Centos 6.6.  
The servers and my VM are running ES 1.3.2.  
The Python interpreter is 3.4.3.  
The Elasticsearch module is 1.6.0

I am able to create an Elasticsearch object using the server cluster nodes or against my VM's IP.  
I am able to create a cluster client and snapshot client using the server cluster nodes or using my local VM's IP.  
I am able to use the URL [http://10.18.0.101:9200/\_cluster/health](http://10.18.0.101:9200/_cluster/health) to get health on my local VM.

```
my_es_client = Elasticsearch(...)
my_snapshot_client = SnapshotClient(my_es_client)
my_cluster_client = ClusterClient(my_es_client)

```

The errors start happening when I try to fetch information from my VM. If I run code like the following, it works against the server but not against my VM (giant stack trace is below).

```
print(my_cluster_client.health())

```

I have tried updating iptables to add a range rule from 9200:9400 (currently only has 9200 and 9300 explicitly). I tried stopping the iptables service. I tried ensuring that my host name is added to hosts on my local workstation and on the VM pointing to the VM's IP (because it's not in DNS). Nothing seems to fix the error. I have tried increasing the timeout value in the client creation.

It appears as though the VM's IP is being translated to the loopback address (127.0.0.1) regardless of whether I use a hostname or a valid IP address.

Any help is appreciated

GET [http://127.0.0.1:9200/\_cluster/health](http://127.0.0.1:9200/_cluster/health) [status:N/A request:1.006s]  
Traceback (most recent call last):  
File "C:\PyVirtEnvirons\ESBackupRestore\lib\site-packages\urllib3\connectionpool.py", line 557, in urlopen  
body=body, headers=headers)  
File "C:\PyVirtEnvirons\ESBackupRestore\lib\site-packages\urllib3\connectionpool.py", line 351, in \_make\_request  
conn.request(method, url, \*\*httplib\_request\_kw)  
File "C:\Python34\Lib\http\client.py", line 1088, in request  
self.\_send\_request(method, url, body, headers)  
File "C:\Python34\Lib\http\client.py", line 1126, in \_send\_request  
self.endheaders(body)  
File "C:\Python34\Lib\http\client.py", line 1084, in endheaders  
self.\_send\_output(message\_body)  
File "C:\Python34\Lib\http\client.py", line 922, in \_send\_output  
self.send(msg)  
File "C:\Python34\Lib\http\client.py", line 857, in send  
self.connect()  
File "C:\PyVirtEnvirons\ESBackupRestore\lib\site-packages\urllib3\connection.py", line 155, in connect  
conn = self.\_new\_conn()  
File "C:\PyVirtEnvirons\ESBackupRestore\lib\site-packages\urllib3\connection.py", line 134, in \_new\_conn  
(self.host, self.port), self.timeout, \*\*extra\_kw)  
File "C:\PyVirtEnvirons\ESBackupRestore\lib\site-packages\urllib3\util\connection.py", line 90, in create\_connection  
raise err  
File "C:\PyVirtEnvirons\ESBackupRestore\lib\site-packages\urllib3\util\connection.py", line 80, in create\_connection  
sock.connect(sa)  
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

During handling of the above exception, another exception occurred:

...

Traceback (most recent call last):  
File "C:/SourceControl/SVN/.../test.py", line 21, in   
print(my\_cluster\_client.health())  
File "C:\PyVirtEnvirons\ESBackupRestore\lib\site-packages\elasticsearch\client\utils.py", line 69, in \_wrapped  
return func(\*args, params=params, \*\*kwargs)  
File "C:\PyVirtEnvirons\ESBackupRestore\lib\site-packages\elasticsearch\client\cluster.py", line 23, in health  
params=params)  
File "C:\PyVirtEnvirons\ESBackupRestore\lib\site-packages\elasticsearch\transport.py", line 307, in perform\_request  
status, headers, data = connection.perform\_request(method, url, params, body, ignore=ignore, timeout=timeout)  
File "C:\PyVirtEnvirons\ESBackupRestore\lib\site-packages\elasticsearch\connection\http\_urllib3.py", line 85, in perform\_request  
raise ConnectionError('N/A', str(e), e)  
elasticsearch.exceptions.ConnectionError: ConnectionError(('Connection aborted.', ConnectionRefusedError(10061, 'No connection could be made because the target machine actively refused it', None, 10061, None))) caused by: ProtocolError(('Connection aborted.', ConnectionRefusedError(10061, 'No connection could be made because the target machine actively refused it', None, 10061, None)))

Process finished with exit code 1

**SOLVED** - restarted the Elasticsearch service on the VM and everything started working. The only change that was still in place when I restarted was the hosts file entry on the server. I verified that this was the problem by removing the entry and restarting the Elasticsearch service and the problem occurred again.

---

<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:** [July 5, 2017, 11:51pm UTC](https://discuss.elastic.co/t/solved-pythons-es-module-getting-connection-refused-on-local-vm-but-not-the-servers/28869/2 "2017-07-05T23:51:38Z")

</div>


