Not able to connect to App search from Python script

We have a problem connecting to our App Search engine from python using the elastic_app_search library. After creating a client instance with our proper credentials the server is rejecting to output anything. For illustration I am using the get_schema method.

from elastic_app_search import Client
client = Client(base_endpoint=base_endpoint,api_key=api_key, use_https=False)
engine_name = "our_engine"

We get the following error:

HTTPConnectionPool(host='https', port=...): Max retries exceeded with url: //... /our_engine/schema (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at ...>: Failed to establish a new connection: [Errno -2] Name or service not known',))

Is there anything we need to adjust in the App search settings to allow it? We should definitely not exceed any limit as we were not connected never before.
The weird thing is that from javascript the connection works fine.

Thank you!

Hello @rishelini

The error tells about the fact the domain cannot be resolved (Name or service not known).

The documentation at this link

Can you please check the value of base_endpoint doesn't contain http:// or https://?
Also, does the host where the python code runs has access to the endpoint? Can you try with a curl?

Hello @Luca_Belluccini,

so I removed the https:// part from the endpoint, that was probably the cause. But ended up with another exception elastic_app_search.exceptions.NonExistentRecord. Is it good?

With curl I was able to reach the endpoint in https:// format with response "You are being redirected" to the login page.

Thank you for your help!

1 Like

I think you managed to connect.

Which one of the methods generated the exception elastic_app_search.exceptions.NonExistentRecord?

The methods I am calling on the Client instance - list_engines, create_engine, get_documents.
In App Search, everything is set up and the engine whose name I am passing to the client contains data which I put there as a json file. I am pretty sure I am entering right engine name - the one that is displayed in App Search under Engines.

Just to clarify:

  1. If your base_endpoint is HTTPS, set use_https=True in the Client initialization.

  2. If you are using the SaaS version available on of App Search, you should use the version 7.5.x of the client.

  3. Checking the code, the only way to get NonExistentRecord is when the request returns HTTP 404.

As the library uses requests library, if you're using Python 3, you can add this at the beginning of your script to log the requests (from StackOverflow). Some details will be in requests.log, others in stdout.

import requests
import logging
from http.client import HTTPConnection
log = logging.getLogger('urllib3')
fh = logging.FileHandler("requests.log")
HTTPConnection.debuglevel = 1
  1. Yes, I am using this setting
    2 . As for the elastic_app_search library, I'm using version 7.6.0.

After I added your script, I found this in the requests.log:

https://my_base_endpoint:443 "GET /engines/our_engine/schema HTTP/1.1" 404 636

When I click on this URL it takes me to the login page and after that on the page with schemas.

Still, really don't know where the problem is.

What is the result of client.list_engines(current=1, size=20)?

Does our_engine contains any special character? (I am not able to tell if this is the actual engine name or you've hidden the engine).

Make sure your base_endpoint looks something like this, excluding the protocol and including /api/as/v1


Now is working!!! thanks!

That was the problem!
Thank you both very much for your help!

1 Like

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