# Connecting to Elasticsearch node in Elastic cloud through python promt

**URL:** <https://discuss.elastic.co/t/connecting-to-elasticsearch-node-in-elastic-cloud-through-python-promt/289028>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-security, language-clients\
**Created:** [November 11, 2021, 10:24pm UTC](https://discuss.elastic.co/t/connecting-to-elasticsearch-node-in-elastic-cloud-through-python-promt/289028 "2021-11-11T22:24:19Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [November 15, 2021, 1:10am UTC](https://discuss.elastic.co/t/connecting-to-elasticsearch-node-in-elastic-cloud-through-python-promt/289028/4 "2021-11-15T01:10:32Z")

</div>

I just did this

```auto
from elasticsearch import Elasticsearch

# you can use RFC-1738 to specify the url

# ... or specify common parameters as kwargs

es = Elasticsearch(
    cloud_id="mycluster:sdfgsdfgdsfgdsfglvdsfgsdfgdsfgmNiM2JkNzRjNDY3JGIxZTUyOWEwNTBkNjRkODZhMzIxZTBhMjU3YjRlODhh",
    http_auth=("elastic", "dsfgsdfgsdfgg"),
)

output = es.info(),

print(output, end=" ")

```

and it worked fine...

This also worked fine...

```auto
es = Elasticsearch(
    cloud_id="mycluster:sdfgsdfgdsfgdsfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgdsfgkODZhMzIxZTBhMjU3YjRlODhh",
    api_key=('cew-IX0BKn301Oe9gPyz', '02I9MJ4OR2GdxYqY3I3cKA'),

```

remember this is NOT and Elastic Cloud API key it is an Elasticsearch API key which can only be created via and API call see [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.15/security-api-create-api-key.html)

```auto
POST /_security/api_key
{
  "name": "my-api-key",
  "expiration": "1d",   
  "role_descriptors": { 
    "role-a": {
      "cluster": ["all"]
      
    }
  }
}

```

results

```auto
{
  "id" : "cew-IX0BKn301Oe9gPyz",
  "name" : "my-api-key",
  "expiration" : 1637026684066,
  "api_key" : "02I9MJ4OR2GdxYqY3I3cKA"
}

```

Please don't anyone worry those are invalid API keys

---

_[View the full topic](https://discuss.elastic.co/t/connecting-to-elasticsearch-node-in-elastic-cloud-through-python-promt/289028)._
