# Unable to connect Elastic Cloud to my python(FastApi) app

**URL:** https://discuss.elastic.co/t/unable-to-connect-elastic-cloud-to-my-python-fastapi-app/322589
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [January 6, 2023, 5:43am UTC](https://discuss.elastic.co/t/unable-to-connect-elastic-cloud-to-my-python-fastapi-app/322589 "2023-01-06T05:43:02Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Dhruv\_Extra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dhruv_extra/32/106190_2.png) [@Dhruv\_Extra](https://discuss.elastic.co/u/Dhruv_Extra)
#### Post date: [January 6, 2023, 5:43am UTC](https://discuss.elastic.co/t/unable-to-connect-elastic-cloud-to-my-python-fastapi-app/322589/1 "2023-01-06T05:43:02Z")

</div>

Here's my code:

```auto
from elasticsearch import Elasticsearch

es = Elasticsearch(
    cloud_id="cluster-1:dXMa5Fx...",
    http_auth=("elastic", "<password>"),
)
es.info()

#or

from elasticsearch import Elasticsearch

es = Elasticsearch(
    cloud_id="cluster-1:dXMa5Fx...",
    api_key=('key's id', 'the key') #I also tried giving just the encoded api key instead of both the id and unencoded key
)
es.info()

#or

from elasticsearch import Elasticsearch

ELASTIC_PASSWORD = "MyPassword"

CLOUD_ID = "My_deployment:blahblahblah"

client = Elasticsearch(cloud_id=CLOUD_ID,
basic_auth=("enterprise_search", ELASTIC_PASSWORD) #not sure if my 
#username is 'elastic' or 'enterprise_search' but I did try both
)

# Successful response!
client.info()
# {'name': 'instance-0000000000', 'cluster_name': ...}

```

I get the same error in all the cases i.e.

NewConnectionError(\<urllib3.connection.HTTPConnection object at 0x000001B33FE91AB0\>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it)

---

<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 3, 2023, 5:44am UTC](https://discuss.elastic.co/t/unable-to-connect-elastic-cloud-to-my-python-fastapi-app/322589/2 "2023-02-03T05:44:00Z")

</div>

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