# Incorrect HTTP method for uri

**URL:** <https://discuss.elastic.co/t/incorrect-http-method-for-uri/320931>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [December 9, 2022, 8:27pm UTC](https://discuss.elastic.co/t/incorrect-http-method-for-uri/320931 "2022-12-09T20:27:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![someusername](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@someusername](https://discuss.elastic.co/u/someusername)\
**Post date:** [December 9, 2022, 8:27pm UTC](https://discuss.elastic.co/t/incorrect-http-method-for-uri/320931/1 "2022-12-09T20:27:12Z")

</div>

Hello,

I want to connect using the python client but I can't figure out what's wrong.

```python
from elasticsearch import Elasticsearch

endpoint = 'https://foo.gcp.cloud.es.io:443/search-addresses/_doc?pipeline=ent-search-generic-ingestion'
api_key = "bar"
api_id = "1568085128"

es_client = Elasticsearch(
    endpoint,
    api_key=(api_id, api_key),
    )

print(es_client.info())
es_client.info()

```

What's the issue? I literally don't understand it. I use the endpoint given to me, I use the api key given to me, I use the python client given to me - why would I get an HTTP request error?

---

<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:** [December 9, 2022, 9:27pm UTC](https://discuss.elastic.co/t/incorrect-http-method-for-uri/320931/2 "2022-12-09T21:27:34Z")

</div>

> [@someusername](#):
>
> `https://foo.gcp.cloud.es.io:443/search-addresses/_doc?pipeline=ent-search-generic-ingestion`

Because that is not the base endpoint.

That's an endpoint to actually ingest document and call an ingest pipeline not to just initiate a client connection.

The endpoint is just  
`https://foo.gcp.cloud.es.io:443`

Perhaps try that... and make sure you get the correct endpoint as there is an `es.` and `kb.` for elasticsearch and kibana respectively

`https://mydeployment.es.us-west1.gcp.cloud.es.io`  
`.....................^^`

Note: I do think it is important to put the port `:443` on the end because some of the clients if a port is not specified it will add `:9200` which is the default elasticsearch port ... but not for Elastic Cloud because of HTTPs

And you can always get the endpoint from the cloud console

 ![Screen Shot 2022-12-09 at 1.51.09 PM](https://us1.discourse-cdn.com/elastic/original/3X/2/b/2bca1e3c260802c46b80ddbd76d55130f0ca3d15.png)

---

<div class="post-metadata">

**Author:** ![someusername](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@someusername](https://discuss.elastic.co/u/someusername)\
**Post date:** [December 10, 2022, 7:14pm UTC](https://discuss.elastic.co/t/incorrect-http-method-for-uri/320931/3 "2022-12-10T19:14:21Z")

</div>

Thanks, I don't think I've ever seen what you show in the screenshot though. I'll give it another try.

---

<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:** [December 10, 2022, 8:29pm UTC](https://discuss.elastic.co/t/incorrect-http-method-for-uri/320931/4 "2022-12-10T20:29:41Z")

</div>

That's from the elastic cloud console where you set up your elastic cloud account and the elastic cloud deployments.

Long story short, it's just a base URL plus 443 that reste of That stuff is actually part of a different API call

---

<div class="post-metadata">

**Author:** ![someusername](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@someusername](https://discuss.elastic.co/u/someusername)\
**Post date:** [December 11, 2022, 4:01pm UTC](https://discuss.elastic.co/t/incorrect-http-method-for-uri/320931/5 "2022-12-11T16:01:18Z")

</div>

Ok so I tried it and I simply can't get it working. I'm so buffled that there isn't simply a straight forward explanation.

1. Are my parameters for the `Elastrichsearch()` correct?
2. I use the `gcp.cloud.es.io:443` endpoint, correct?
3. I Create a new API key. The value is the actualy key but what is the id? I tried both, the `name` and the `user`.

I still get 401. I really really don't understand the issue. Why can't I simply connect by API key like you'd do it when using curl?

---

<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:** [December 11, 2022, 4:07pm UTC](https://discuss.elastic.co/t/incorrect-http-method-for-uri/320931/6 "2022-12-11T16:07:53Z")

</div>

Take a look at this ...

> [@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…

OK I just tested this and all works as expected.

```auto
POST /_security/api_key
{
  "name": "my-discuss-api-key",
  "expiration": "1d",   
  "role_descriptors": { 
    "role-a": {
      "cluster": ["all"]
      
    }
  }
}
# Result
{
  "id": "sadfasdfGGJCaJCcrUTy",
  "name": "my-discuss-api-key",
  "expiration": 1670861752818,
  "api_key": "asfdasdf9YOve4r3g",
  "encoded": "cXlINEFZVUJHR0pDYUpDY3JVVHk6Q3JEeTNfbC1SdHVEMzlZT3ZlNHIzZw=="
}

```

Both Options Work

```auto
from elasticsearch import Elasticsearch

es = Elasticsearch(
	  "https://my-demo-cluster.es.us-west1.gcp.cloud.es.io:443",
    api_key=("sadfasdfGGJCaJCcrUTy", "asfdasdf9YOve4r3g"),
)

# es = Elasticsearch(
# cloud_id="my-demo-cluster:asdfsadfasdfkLmVzLmlvJDA1M2Y1MWYwMDViOTRjNDA4NGMzNmNiM2JkNzRjNDY3JGIxZTUyOWEwNTBkNjRkODZhMzIxZTBhMjU3YjRlODhh",
# api_key=("sadfasdfGGJCaJCcrUTy", "asfdasdf9YOve4r3g"),
# )

output = es.info(),

print(output, end=" ")

```

```auto
(ObjectApiResponse({'name': 'instance-0000000095', 'cluster_name': 'sadfsadf4c4084c36cb3bd74c467', 'cluster_uuid': 'sadfsadfa-k2eXlBQ', 'version': {'number': '8.5.3', 'build_flavor': 'default', 'build_type': 'docker', 'build_hash': '4ed5ee9afac63de92ec98f404ccbed7d3ba9584e', 'build_date': '2022-12-05T18:22:22.226119656Z', 'build_snapshot': False, 'lucene_version': '9.4.2', 'minimum_wire_compatibility_version': '7.17.0', 'minimum_index_compatibility_version': '7.0.0'}, 'tagline': 'You Know, for Search'}),)

```

**Exactly** what error are you getting. when you state it is not working you have to show the exact code and the error messages otherwise we are just guessing.

---

<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:** [January 8, 2023, 4:08pm UTC](https://discuss.elastic.co/t/incorrect-http-method-for-uri/320931/7 "2023-01-08T16:08:14Z")

</div>

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