Take a look at this ...
OK I just tested this and all works as expected.
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
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=" ")
(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.