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

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 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 [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.