httpx.ConnectError: [Errno 111] Connection refused #1

Closed
opened 2026-02-15 16:27:22 -05:00 by yindo · 3 comments
Owner

Originally created by @asmith26 on GitHub (Jan 17, 2024).

Hi there,

I'm trying to run simple-chat-stream example, but unfortunately I'm geeting

Traceback (most recent call last):
  File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpcore/_exceptions.py", line 10, in map_exceptions
    yield
  File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpcore/_backends/sync.py", line 206, in connect_tcp
    sock = socket.create_connection(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/mambaforge/envs/panel-apps/lib/python3.11/socket.py", line 851, in create_connection
    raise exceptions[0]
  File "~/mambaforge/envs/panel-apps/lib/python3.11/socket.py", line 836, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpx/_transports/default.py", line 66, in map_httpcore_exceptions
    yield
  File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpx/_transports/default.py", line 228, in handle_request
    resp = self._pool.handle_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 268, in handle_request
    raise exc
  File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 251, in handle_request
    response = connection.handle_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 99, in handle_request
    raise exc
  File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 76, in handle_request
    stream = self._connect(request)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 124, in _connect
    stream = self._network_backend.connect_tcp(**kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpcore/_backends/sync.py", line 205, in connect_tcp
    with map_exceptions(exc_map):
  File "~/mambaforge/envs/panel-apps/lib/python3.11/contextlib.py", line 158, in __exit__
    self.gen.throw(typ, value, traceback)
  File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc) from exc
httpcore.ConnectError: [Errno 111] Connection refused

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "~/git/panel-apps/main.py", line 11, in <module>
    for part in chat('mistral', messages=messages, stream=True):
  File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/ollama/_client.py", line 64, in _stream
    with self._client.stream(method, url, **kwargs) as r:
  File "~/mambaforge/envs/panel-apps/lib/python3.11/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpx/_client.py", line 857, in stream
    response = self.send(
               ^^^^^^^^^^
  File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpx/_client.py", line 901, in send
    response = self._send_handling_auth(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpx/_client.py", line 929, in _send_handling_auth
    response = self._send_handling_redirects(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpx/_client.py", line 966, in _send_handling_redirects
    response = self._send_single_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpx/_client.py", line 1002, in _send_single_request
    response = transport.handle_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpx/_transports/default.py", line 227, in handle_request
    with map_httpcore_exceptions():
  File "~/mambaforge/envs/panel-apps/lib/python3.11/contextlib.py", line 158, in __exit__
    self.gen.throw(typ, value, traceback)
  File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpx/_transports/default.py", line 83, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ConnectError: [Errno 111] Connection refused

I'm using ollama = 0.1.2 and have tried running ollama.pull("mistral").

Many thanks for any help!

Originally created by @asmith26 on GitHub (Jan 17, 2024). Hi there, I'm trying to run [simple-chat-stream example](https://github.com/jmorganca/ollama-python/tree/main/examples/simple-chat-stream), but unfortunately I'm geeting ```python Traceback (most recent call last): File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpcore/_exceptions.py", line 10, in map_exceptions yield File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpcore/_backends/sync.py", line 206, in connect_tcp sock = socket.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "~/mambaforge/envs/panel-apps/lib/python3.11/socket.py", line 851, in create_connection raise exceptions[0] File "~/mambaforge/envs/panel-apps/lib/python3.11/socket.py", line 836, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused The above exception was the direct cause of the following exception: Traceback (most recent call last): File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpx/_transports/default.py", line 66, in map_httpcore_exceptions yield File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpx/_transports/default.py", line 228, in handle_request resp = self._pool.handle_request(req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 268, in handle_request raise exc File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 251, in handle_request response = connection.handle_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 99, in handle_request raise exc File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 76, in handle_request stream = self._connect(request) ^^^^^^^^^^^^^^^^^^^^^^ File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 124, in _connect stream = self._network_backend.connect_tcp(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpcore/_backends/sync.py", line 205, in connect_tcp with map_exceptions(exc_map): File "~/mambaforge/envs/panel-apps/lib/python3.11/contextlib.py", line 158, in __exit__ self.gen.throw(typ, value, traceback) File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions raise to_exc(exc) from exc httpcore.ConnectError: [Errno 111] Connection refused The above exception was the direct cause of the following exception: Traceback (most recent call last): File "~/git/panel-apps/main.py", line 11, in <module> for part in chat('mistral', messages=messages, stream=True): File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/ollama/_client.py", line 64, in _stream with self._client.stream(method, url, **kwargs) as r: File "~/mambaforge/envs/panel-apps/lib/python3.11/contextlib.py", line 137, in __enter__ return next(self.gen) ^^^^^^^^^^^^^^ File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpx/_client.py", line 857, in stream response = self.send( ^^^^^^^^^^ File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpx/_client.py", line 901, in send response = self._send_handling_auth( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpx/_client.py", line 929, in _send_handling_auth response = self._send_handling_redirects( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpx/_client.py", line 966, in _send_handling_redirects response = self._send_single_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpx/_client.py", line 1002, in _send_single_request response = transport.handle_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpx/_transports/default.py", line 227, in handle_request with map_httpcore_exceptions(): File "~/mambaforge/envs/panel-apps/lib/python3.11/contextlib.py", line 158, in __exit__ self.gen.throw(typ, value, traceback) File "~/mambaforge/envs/panel-apps/lib/python3.11/site-packages/httpx/_transports/default.py", line 83, in map_httpcore_exceptions raise mapped_exc(message) from exc httpx.ConnectError: [Errno 111] Connection refused ``` I'm using `ollama = 0.1.2` and have tried running `ollama.pull("mistral")`. Many thanks for any help!
yindo closed this issue 2026-02-15 16:27:22 -05:00
Author
Owner

@asmith26 commented on GitHub (Jan 18, 2024):

Ah, I've just realised I need to run ollama in the background.

I'll close this ticket - let me know if I can with something like add this to the README or enhancing the error message with this info.

Many thanks for these amazing libs!

@asmith26 commented on GitHub (Jan 18, 2024): Ah, I've just realised I need to run [ollama](https://github.com/jmorganca/ollama) in the background. I'll close this ticket - let me know if I can with something like add this to the README or enhancing the error message with this info. Many thanks for these amazing libs!
Author
Owner

@abisheka-pitumpe commented on GitHub (Apr 4, 2024):

How do I run ollama in the background in a python environment? I know that ollama serve works on CLI, I am getting the same Error 111 in an environment where I can only use ollama-python and not CLI.

@abisheka-pitumpe commented on GitHub (Apr 4, 2024): How do I run ollama in the background in a python environment? I know that `ollama serve` works on CLI, I am getting the same Error 111 in an environment where I can only use ollama-python and not CLI.
Author
Owner

@ValeWalker27 commented on GitHub (Apr 23, 2024):

How do I run ollama in the background in a python environment? I know that ollama serve works on CLI, I am getting the same Error 111 in an environment where I can only use ollama-python and not CLI.

I'm not an expert but may be you can try running a Custom client and refer to it in your said environment.
Ref: https://ollama.com/blog/python-javascript-libraries

ollama = Client(host='my.ollama.host')

Hope it helps.

@ValeWalker27 commented on GitHub (Apr 23, 2024): > How do I run ollama in the background in a python environment? I know that `ollama serve` works on CLI, I am getting the same Error 111 in an environment where I can only use ollama-python and not CLI. I'm not an expert but may be you can try running a Custom client and refer to it in your said environment. Ref: https://ollama.com/blog/python-javascript-libraries ollama = Client(host='my.ollama.host') Hope it helps.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ollama/ollama-python#1