Support Center

Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

Unauthorised Access error when accessing API access key via Python

Vit Jul 23, 2019 05:25PM +03

I have created a read-only access key for an index (hosted on Heroku). I can connect to the supplied URL via the browser (only using the non-SSL http:// link though, SSL always gives me "Unauthorized access" errors).

In Python, ElasticSearch defaults to port 9200, so I have to manually specify a different port, which seems to be 80 for non-SSL connection.

When I try to connect to it via Python (non-SSL, using port 80), I get an error:[{"code":90,"message":"Unauthorized access"}]. Not specifying a port defaults to 9200 I believe and simply times out.

If I use the original API key (non-SSL with port 80), I can connect, but I don't want to use it since I only want to run search queries.

So how can I use the read-only API access key to connect via Python and port 80? Maybe there's another port for non-browser connection, then what is it?

Up 0 rated Down
Ferhat Sobay Jul 23, 2019 05:33PM +03 Searchly Agent

SSL port is 443 and non-ssl is as you mentioned is 80, so both should work.

For access-keys, since they are scoped with index or alias, you need to ensure providing them at request.

So for instance using access key the request;

curl -XGET will fail but curl -XGET will succeed.

Can you please share your code piece related connection section ?

Up 0 rated Down
Vit Jul 23, 2019 06:15PM +03
Port 443 didn't help me establish an SSL connection in my previous attempts.

The python code is
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search

client = Elasticsearch({SEARCHBOX_URL with AccessKey swapped out}, port=80)
This works for the main SEARCHBOX_URL, but not for the one with the read-only access key.

By the way, the Connection URL Searchly provides for the read-only Access Key doesn't work in the browser for me, gives the same Unauthorized access error. The only way I can connect is to swap out the API key from the main SEARCHBOX_URL.
Up 0 rated Down
Ferhat Sobay Jul 23, 2019 07:18PM +03 Searchly Agent
I think you need to remove "" thus root access not available with access keys.

Just checked and ssl needs;

client = Elasticsearch({SEARCHBOX_URL with AccessKey swapped out}, port=443, use_ssl=True)

please see


Post Your Public Answer

Your name (required)
Your email address (required)
Answer (required)
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
Invalid characters found