# How to get http status code | Python

**URL:** <https://discuss.elastic.co/t/how-to-get-http-status-code-python/366915>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [September 22, 2024, 7:46am UTC](https://discuss.elastic.co/t/how-to-get-http-status-code-python/366915 "2024-09-22T07:46:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aniket\_Pant](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@Aniket\_Pant](https://discuss.elastic.co/u/Aniket_Pant)\
**Post date:** [September 22, 2024, 7:46am UTC](https://discuss.elastic.co/t/how-to-get-http-status-code-python/366915/1 "2024-09-22T07:46:06Z")

</div>

Hi Team

I want to get status code while connecting to cluster.

```auto
from elasticsearch import Elasticsearch

client = Elasticsearch(
    "https://0.0.0.0.:9200",
    basic_auth=("elastic", "elastic"),
    verify_certs=False
)
print(client.status_code)

```

```auto
Traceback (most recent call last):
  File "connection.py", line 8, in <module>
    print(client.status_code)
AttributeError: 'Elasticsearch' object has no attribute 'status_code'

```

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [September 22, 2024, 5:06pm UTC](https://discuss.elastic.co/t/how-to-get-http-status-code-python/366915/2 "2024-09-22T17:06:24Z")

</div>

You need to connect to Elasticsearch to get a responde, setting up a client does nothing, just instantiate a client to be used when making requests to the cluster.

Also, I don't think the requests will return the status code.

If you want to check the connectivity with your cluster use something like this:

```auto
from elasticsearch import Elasticsearch

client = Elasticsearch(
    "https://localhost:9200",
    basic_auth=("elastic", "elastic"),
    verify_certs=False
)

resp = client.info()
print(resp)

```

You can also check some examples on how to use the python client [here](https://www.elastic.co/guide/en/elasticsearch/client/python-api/current/examples.html).

---

<div class="post-metadata">

**Author:** ![Quentin\_Pradet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/quentin_pradet/32/94192_2.png) [@Quentin\_Pradet](https://discuss.elastic.co/u/Quentin_Pradet)\
**Post date:** [September 23, 2024, 7:22am UTC](https://discuss.elastic.co/t/how-to-get-http-status-code-python/366915/3 "2024-09-23T07:22:58Z")

</div>

Additionally, when you have a response (like `resp` above), you can use `resp.meta.status` to get the status code. This is documented in [Configuration | Elasticsearch Python Client [8.15] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/python-api/current/config.html#_ignoring_status_codes).
