You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my projects RestAPI I have a function called "search" which makes a request to SOLR to get some search results. To make the request I use Pysolr. Normally all my project components run in the same Docker network but when I run my RestAPI tests using Pytest the RestAPI is started separately. Pysolr then tries to connect to my SOLR Nodes using the Docker container names, which will obviously not work.
What I want
I need Pysolr to connect to the SOLR Node using localhost, but I can't figure out how to get this working.
What I tried
I tried to change my docker-compose-override.yml file in a way that my SOLR Nodes are running on localhost and not on their docker names. And I tried to change the various environment variables for the Zookeeper and SOLR servers / hosts to use localhost. I also tried to somehow set in Pysolr directly the SOLR Nodes.
What I expected
I expected that Pysolr would use localhost:Port to connect to the SOLR Nodes.
pysolr:pysolr.py:428 Failed to connect to server at http://search2:8984/solr/tag/select/?q=test-tag&start=0&rows=100&wt=json: HTTPConnectionPool(host='search2', port=8984): Max retries exceeded with url: /solr/tag/select/?q=test-tag&start=0&rows=100&wt=json (Caused by NameResolutionError("<urllib3.connection.HTTPConnection object at 0x10ba89fd0>: Failed to resolve 'search2' ([Errno 8] nodename nor servname provided, or not known)"))
Traceback (most recent call last):
File "/restapi/.venv/lib/python3.13/site-packages/urllib3/connection.py", line 199, in _new_conn
sock = connection.create_connection(
(self._dns_host, self.port),
...<2 lines>...
socket_options=self.socket_options,
)
File "/restapi/.venv/lib/python3.13/site-packages/urllib3/util/connection.py", line 60, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.pyenv/versions/3.13.1/lib/python3.13/socket.py", line 975, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/restapi/.venv/lib/python3.13/site-packages/urllib3/connectionpool.py", line 789, in urlopen
response = self._make_request(
conn,
...<10 lines>...
**response_kw,
)
File "/restapi/.venv/lib/python3.13/site-packages/urllib3/connectionpool.py", line 495, in _make_request
conn.request(
~~~~~~~~~~~~^
method,
^^^^^^^
...<6 lines>...
enforce_content_length=enforce_content_length,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/restapi/.venv/lib/python3.13/site-packages/urllib3/connection.py", line 441, in request
self.endheaders()
~~~~~~~~~~~~~~~^^
File "/.pyenv/versions/3.13.1/lib/python3.13/http/client.py", line 1331, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.pyenv/versions/3.13.1/lib/python3.13/http/client.py", line 1091, in _send_output
self.send(msg)
~~~~~~~~~^^^^^
File "/.pyenv/versions/3.13.1/lib/python3.13/http/client.py", line 1035, in send
self.connect()
~~~~~~~~~~~~^^
File "/restapi/.venv/lib/python3.13/site-packages/urllib3/connection.py", line 279, in connect
self.sock = self._new_conn()
~~~~~~~~~~~~~~^^
File "/restapi/.venv/lib/python3.13/site-packages/urllib3/connection.py", line 206, in _new_conn
raise NameResolutionError(self.host, self, e) from e
urllib3.exceptions.NameResolutionError: <urllib3.connection.HTTPConnection object at 0x10ba89fd0>: Failed to resolve 'search2' ([Errno 8] nodename nor servname provided, or not known)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/restapi/.venv/lib/python3.13/site-packages/requests/adapters.py", line 667, in send
resp = conn.urlopen(
method=request.method,
...<9 lines>...
chunked=chunked,
)
File "/restapi/.venv/lib/python3.13/site-packages/urllib3/connectionpool.py", line 843, in urlopen
retries = retries.increment(
method, url, error=new_e, _pool=self, _stacktrace=sys.exc_info()[2]
)
File "/restapi/.venv/lib/python3.13/site-packages/urllib3/util/retry.py", line 519, in increment
raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='search2', port=8984): Max retries exceeded with url: /solr/tag/select/?q=test-tag&start=0&rows=100&wt=json (Caused by NameResolutionError("<urllib3.connection.HTTPConnection object at 0x10ba89fd0>: Failed to resolve 'search2' ([Errno 8] nodename nor servname provided, or not known)"))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/restapi/.venv/lib/python3.13/site-packages/pysolr.py", line 414, in _send_request
resp = requests_method(
url,
...<4 lines>...
auth=self.auth,
)
File "/restapi/.venv/lib/python3.13/site-packages/requests/sessions.py", line 602, in get
return self.request("GET", url, **kwargs)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/restapi/.venv/lib/python3.13/site-packages/requests/sessions.py", line 589, in request
resp = self.send(prep, **send_kwargs)
File "/restapi/.venv/lib/python3.13/site-packages/requests/sessions.py", line 703, in send
r = adapter.send(request, **kwargs)
File "/restapi/.venv/lib/python3.13/site-packages/requests/adapters.py", line 700, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='search2', port=8984): Max retries exceeded with url: /solr/tag/select/?q=test-tag&start=0&rows=100&wt=json (Caused by NameResolutionError("<urllib3.connection.HTTPConnection object at 0x10ba89fd0>: Failed to resolve 'search2' ([Errno 8] nodename nor servname provided, or not known)"))
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Structure
The Problem
In my projects RestAPI I have a function called "search" which makes a request to SOLR to get some search results. To make the request I use Pysolr. Normally all my project components run in the same Docker network but when I run my RestAPI tests using Pytest the RestAPI is started separately. Pysolr then tries to connect to my SOLR Nodes using the Docker container names, which will obviously not work.
What I want
I need Pysolr to connect to the SOLR Node using localhost, but I can't figure out how to get this working.
What I tried
I tried to change my docker-compose-override.yml file in a way that my SOLR Nodes are running on localhost and not on their docker names. And I tried to change the various environment variables for the Zookeeper and SOLR servers / hosts to use localhost. I also tried to somehow set in Pysolr directly the SOLR Nodes.
What I expected
I expected that Pysolr would use localhost:Port to connect to the SOLR Nodes.
Code
docker-compose.yml
docker-compose-override.yml
search.py
Trace back
Beta Was this translation helpful? Give feedback.
All reactions