# Connect to Elastic Cloud using python client

**URL:** https://discuss.elastic.co/t/connect-to-elastic-cloud-using-python-client/330875
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [April 26, 2023, 6:56pm UTC](https://discuss.elastic.co/t/connect-to-elastic-cloud-using-python-client/330875 "2023-04-26T18:56:22Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Venkatesh\_Guruprasad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/venkatesh_guruprasad/32/50887_2.png) [@Venkatesh\_Guruprasad](https://discuss.elastic.co/u/Venkatesh_Guruprasad)
#### Post date: [April 26, 2023, 6:56pm UTC](https://discuss.elastic.co/t/connect-to-elastic-cloud-using-python-client/330875/1 "2023-04-26T18:56:22Z")

</div>

I am using python client to connect to Elastic Cloud. I have tried connecting using basic\_auth and api\_keys. In both instances it gives me the following error

elasticsearch.AuthorizationException: AuthorizationException(403, "{'ok': False, 'message': 'Forbidden'}")

Here is the sample code:

\<\< from elasticsearch import Elasticsearch

es = Elasticsearch(cloud\_id=\<\<\>\>, api\_key=(api\_key\_id, api\_key))

es = Elasticsearch(cloud\_id=\<\<\>\>, basic\_auth=(username, password)) \>\>

Can someone help me with this?

---

<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: [April 26, 2023, 7:22pm UTC](https://discuss.elastic.co/t/connect-to-elastic-cloud-using-python-client/330875/2 "2023-04-26T19:22:14Z")

</div>

Hi @Venkatesh_Guruprasad

Perhaps take a look at this thread

> [@Connecting to Elasticsearch node in Elastic cloud through python promt](https://discuss.elastic.co/t/connecting-to-elasticsearch-node-in-elastic-cloud-through-python-promt/289028/4):
>
> I just did this 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... es = Elasticsearch( cloud\_id="mycluster:sdfgsdfgdsfgdsfgsdfgsdfgsdfgsdfg…

Perhaps you are using the wrong type of API Key as this user was

> 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/8.7/security-api-create-api-key.html)

Actually API Keys can now be created via Kibana -\> Stack Management -\> API Keys as well now

---

<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: [May 24, 2023, 7:22pm UTC](https://discuss.elastic.co/t/connect-to-elastic-cloud-using-python-client/330875/3 "2023-05-24T19:22:51Z")

</div>

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