Ollama Python client mostly broken on Windows 11 #227

Closed
opened 2026-02-15 16:28:52 -05:00 by yindo · 4 comments
Owner

Originally created by @maglore9900 on GitHub (Feb 26, 2025).

Most of the ollama client functions appear to be broken only on Windows. I first learned of a potential issue from a user in the Ollama discord about 48 hours ago.

However, I didnt see the issue (as I do not normally use the python client) until I tried to test out the Minion stuff mentioned in today's announcement.

I tested the following examples:

TEST 1

  response: ChatResponse = chat(model='llama3.2:3b', messages=[
    {
      'role': 'user',
      'content': 'Why is the sky blue?',
    },
  ])
  print(response)

The above code results in:

Traceback (most recent call last):
  File "C:\Python312\Lib\site-packages\httpx\_transports\default.py", line 72, in map_httpcore_exceptions
    yield
  File "C:\Python312\Lib\site-packages\httpx\_transports\default.py", line 236, in handle_request
    resp = self._pool.handle_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\httpcore\_sync\connection_pool.py", line 216, in handle_request
    raise exc from None
  File "C:\Python312\Lib\site-packages\httpcore\_sync\connection_pool.py", line 196, in handle_request
    response = connection.handle_request(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\httpcore\_sync\connection.py", line 99, in handle_request
    raise exc
  File "C:\Python312\Lib\site-packages\httpcore\_sync\connection.py", line 76, in handle_request
    stream = self._connect(request)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\httpcore\_sync\connection.py", line 122, in _connect
    stream = self._network_backend.connect_tcp(**kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\httpcore\_backends\sync.py", line 205, in connect_tcp
    with map_exceptions(exc_map):
  File "C:\Python312\Lib\contextlib.py", line 158, in __exit__
    self.gen.throw(value)
  File "C:\Python312\Lib\site-packages\httpcore\_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc) from exc
httpcore.ConnectError: [WinError 10049] The requested address is not valid in its context

TEST 2

  client = Client(
    host='http://localhost:11434',
    headers={'x-some-header': 'some-value'}
  )
  response = client.chat(model='llama3.2:3b', messages=[
    {
      'role': 'user',
      'content': 'Why is the sky blue?',
    },
  ])

  print(response)

This succeeds

TEST 3

print(ollama.ps())

The above code results in

Traceback (most recent call last):
  File "C:\Python312\Lib\site-packages\httpx\_transports\default.py", line 72, in map_httpcore_exceptions
    yield
  File "C:\Python312\Lib\site-packages\httpx\_transports\default.py", line 236, in handle_request
    resp = self._pool.handle_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\httpcore\_sync\connection_pool.py", line 216, in handle_request
    raise exc from None
  File "C:\Python312\Lib\site-packages\httpcore\_sync\connection_pool.py", line 196, in handle_request
    response = connection.handle_request(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\httpcore\_sync\connection.py", line 99, in handle_request
    raise exc
  File "C:\Python312\Lib\site-packages\httpcore\_sync\connection.py", line 76, in handle_request
    stream = self._connect(request)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\httpcore\_sync\connection.py", line 122, in _connect
    stream = self._network_backend.connect_tcp(**kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\httpcore\_backends\sync.py", line 205, in connect_tcp
    with map_exceptions(exc_map):
  File "C:\Python312\Lib\contextlib.py", line 158, in __exit__
    self.gen.throw(value)
  File "C:\Python312\Lib\site-packages\httpcore\_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc) from exc
httpcore.ConnectError: [WinError 10049] The requested address is not valid in its context

ADDITIONAL INFO:
I tested in both command shell and powershell, results are the same, but command shows less verbose errors

I checked the server and app logs, no issues found.

I used ollama run llama3.2:3b on the same machine from powershell and it worked fine

One thing I noticed was that when using ollama CLI the server log updates, but I didnt see it update from the ollama client. (not sure about the successful one)

I also tested the exact same code on Ubuntu and they all succeeded

Originally created by @maglore9900 on GitHub (Feb 26, 2025). Most of the ollama client functions appear to be broken only on Windows. I first learned of a potential issue from a user in the Ollama discord about 48 hours ago. However, I didnt see the issue (as I do not normally use the python client) until I tried to test out the Minion stuff mentioned in today's announcement. I tested the following examples: TEST 1 ``` response: ChatResponse = chat(model='llama3.2:3b', messages=[ { 'role': 'user', 'content': 'Why is the sky blue?', }, ]) print(response) ``` The above code results in: ``` Traceback (most recent call last): File "C:\Python312\Lib\site-packages\httpx\_transports\default.py", line 72, in map_httpcore_exceptions yield File "C:\Python312\Lib\site-packages\httpx\_transports\default.py", line 236, in handle_request resp = self._pool.handle_request(req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python312\Lib\site-packages\httpcore\_sync\connection_pool.py", line 216, in handle_request raise exc from None File "C:\Python312\Lib\site-packages\httpcore\_sync\connection_pool.py", line 196, in handle_request response = connection.handle_request( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python312\Lib\site-packages\httpcore\_sync\connection.py", line 99, in handle_request raise exc File "C:\Python312\Lib\site-packages\httpcore\_sync\connection.py", line 76, in handle_request stream = self._connect(request) ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python312\Lib\site-packages\httpcore\_sync\connection.py", line 122, in _connect stream = self._network_backend.connect_tcp(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python312\Lib\site-packages\httpcore\_backends\sync.py", line 205, in connect_tcp with map_exceptions(exc_map): File "C:\Python312\Lib\contextlib.py", line 158, in __exit__ self.gen.throw(value) File "C:\Python312\Lib\site-packages\httpcore\_exceptions.py", line 14, in map_exceptions raise to_exc(exc) from exc httpcore.ConnectError: [WinError 10049] The requested address is not valid in its context ``` TEST 2 ``` client = Client( host='http://localhost:11434', headers={'x-some-header': 'some-value'} ) response = client.chat(model='llama3.2:3b', messages=[ { 'role': 'user', 'content': 'Why is the sky blue?', }, ]) print(response) ``` This succeeds TEST 3 ``` print(ollama.ps()) ``` The above code results in ``` Traceback (most recent call last): File "C:\Python312\Lib\site-packages\httpx\_transports\default.py", line 72, in map_httpcore_exceptions yield File "C:\Python312\Lib\site-packages\httpx\_transports\default.py", line 236, in handle_request resp = self._pool.handle_request(req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python312\Lib\site-packages\httpcore\_sync\connection_pool.py", line 216, in handle_request raise exc from None File "C:\Python312\Lib\site-packages\httpcore\_sync\connection_pool.py", line 196, in handle_request response = connection.handle_request( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python312\Lib\site-packages\httpcore\_sync\connection.py", line 99, in handle_request raise exc File "C:\Python312\Lib\site-packages\httpcore\_sync\connection.py", line 76, in handle_request stream = self._connect(request) ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python312\Lib\site-packages\httpcore\_sync\connection.py", line 122, in _connect stream = self._network_backend.connect_tcp(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python312\Lib\site-packages\httpcore\_backends\sync.py", line 205, in connect_tcp with map_exceptions(exc_map): File "C:\Python312\Lib\contextlib.py", line 158, in __exit__ self.gen.throw(value) File "C:\Python312\Lib\site-packages\httpcore\_exceptions.py", line 14, in map_exceptions raise to_exc(exc) from exc httpcore.ConnectError: [WinError 10049] The requested address is not valid in its context ``` ADDITIONAL INFO: I tested in both command shell and powershell, results are the same, but command shows less verbose errors I checked the server and app logs, no issues found. I used `ollama run llama3.2:3b` on the same machine from powershell and it worked fine One thing I noticed was that when using ollama CLI the server log updates, but I didnt see it update from the ollama client. (not sure about the successful one) I also tested the exact same code on Ubuntu and they all succeeded
yindo closed this issue 2026-02-15 16:28:52 -05:00
Author
Owner

@xuzexin-hz commented on GitHub (Mar 5, 2025):

error:httpcore.ConnectError: [WinError 10049] The requested address is not valid in its context

So you can debug and see what URL is being accessed? Or confirm the OLLAMA_HOST system variable. What is actually accessed by the ollama. ps() command http://localhost:11434/api/ps. The most effective way is debug

@xuzexin-hz commented on GitHub (Mar 5, 2025): error:httpcore.ConnectError: [WinError 10049] The requested address is not valid in its context So you can debug and see what URL is being accessed? Or confirm the OLLAMA_HOST system variable. What is actually accessed by the ollama. ps() command http://localhost:11434/api/ps. The most effective way is debug
Author
Owner

@maglore9900 commented on GitHub (Mar 5, 2025):

error:httpcore.ConnectError: [WinError 10049] The requested address is not valid in its context

So you can debug and see what URL is being accessed? Or confirm the OLLAMA_HOST system variable. What is actually accessed by the ollama. ps() command http://localhost:11434/api/ps. The most effective way is debug

The Ollama instance is local in both test cases (windows and linux), the CLI works fine. The python client does not work on windows when you cannot specific the host (even though its local)

@maglore9900 commented on GitHub (Mar 5, 2025): > error:httpcore.ConnectError: [WinError 10049] The requested address is not valid in its context > > So you can debug and see what URL is being accessed? Or confirm the OLLAMA_HOST system variable. What is actually accessed by the ollama. ps() command http://localhost:11434/api/ps. The most effective way is debug The Ollama instance is local in both test cases (windows and linux), the CLI works fine. The python client does not work on windows when you cannot specific the host (even though its local)
Author
Owner

@lemassykoi commented on GitHub (Mar 5, 2025):

I'm using Ollama-python for months, and I never had this error. I'm always specifying host in python. The ENV variable was not used/set in my windows dev box.

I tried the TEST1 from OP, and it fails with another error :

ConnectionError: Failed to connect to Ollama. Please check that Ollama is downloaded, running and accessible. https://ollama.com/download

then I read https://github.com/ollama/ollama-python/issues/450#issuecomment-2700283951 and I set the env var OLLAMA_HOST : os.environ['OLLAMA_HOST'] = 'http://127.0.0.1:11434'

after that, I ran TEST1 without error:

Image

@lemassykoi commented on GitHub (Mar 5, 2025): I'm using Ollama-python for months, and I never had this error. I'm always specifying host in python. The ENV variable was not used/set in my windows dev box. I tried the TEST1 from OP, and it fails with another error : ``` ConnectionError: Failed to connect to Ollama. Please check that Ollama is downloaded, running and accessible. https://ollama.com/download ``` then I read [https://github.com/ollama/ollama-python/issues/450#issuecomment-2700283951](url) and I set the env var OLLAMA_HOST : ```os.environ['OLLAMA_HOST'] = 'http://127.0.0.1:11434'``` after that, I ran TEST1 without error: ![Image](https://github.com/user-attachments/assets/6716190b-c9ca-48ef-932d-c41ff699ecd3)
Author
Owner

@ParthSareen commented on GitHub (Apr 9, 2025):

This is expected behavior - probably surfaced with the httpx bump from a bit ago.

OLLAMA_HOST should not be 0.0.0.0 from the client side.

See:
https://github.com/ollama/ollama-python/pull/491#issuecomment-2790636938

@ParthSareen commented on GitHub (Apr 9, 2025): This is expected behavior - probably surfaced with the httpx bump from a bit ago. `OLLAMA_HOST` should not be `0.0.0.0` from the client side. See: https://github.com/ollama/ollama-python/pull/491#issuecomment-2790636938
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ollama/ollama-python#227