response error when calling any ollama functions #50

Open
opened 2026-02-15 16:27:43 -05:00 by yindo · 5 comments
Owner

Originally created by @Hansyvea on GitHub (Mar 10, 2024).

I have ollama service run in the background and it is working well to run any model in ternimal.
However, when it comes to python, things happend.

import ollama
ollama.list()

site-packages/ollama/_client.py:71) response.raise_for_status()
site-packages/ollama/_client.py:72) except httpx.HTTPStatusError as e:
--->site-packages/ollama/_client.py:73) raise ResponseError(e.response.text, e.response.status_code) from None
site-packages/ollama/_client.py:75) return response

Originally created by @Hansyvea on GitHub (Mar 10, 2024). I have ollama service run in the background and it is working well to run any model in ternimal. However, when it comes to python, things happend. ```python import ollama ollama.list() ``` site-packages/ollama/_client.py:71) response.raise_for_status() site-packages/ollama/_client.py:72) except httpx.HTTPStatusError as e: --->site-packages/ollama/_client.py:73) raise ResponseError(e.response.text, e.response.status_code) from None site-packages/ollama/_client.py:75) return response
Author
Owner

@mxyng commented on GitHub (Mar 19, 2024):

Are you using the standard ollama host/port, e.g. 127.0.0.1:11434? If not, you will need to set OLLAMA_HOST or ollama.Client(host='...')

@mxyng commented on GitHub (Mar 19, 2024): Are you using the standard ollama host/port, e.g. `127.0.0.1:11434`? If not, you will need to set `OLLAMA_HOST` or `ollama.Client(host='...')`
Author
Owner

@CufeDigitalEcon commented on GitHub (Apr 24, 2024):

try turn off your VPN app

@CufeDigitalEcon commented on GitHub (Apr 24, 2024): try turn off your VPN app
Author
Owner

@edgemoorlf commented on GitHub (Apr 25, 2024):

try turn off your VPN app

Thanks, buddy. You made my day!

Wondering why? REST call to http://127.0.0.1:11434/api/embeddings was ok on the same machine.

@edgemoorlf commented on GitHub (Apr 25, 2024): > try turn off your VPN app Thanks, buddy. You made my day! Wondering why? REST call to http://127.0.0.1:11434/api/embeddings was ok on the same machine.
Author
Owner

@burceasn commented on GitHub (Oct 21, 2024):

I've meet the same question, and i turn off my VPN but still not working.
Could you give me any clue?

@burceasn commented on GitHub (Oct 21, 2024): I've meet the same question, and i turn off my VPN but still not working. Could you give me any clue?
Author
Owner

@bsharper commented on GitHub (Jun 19, 2025):

I figured out the issue: OLLAMA_HOST tells the ollama server where to listen. However, there are addresses (like 0.0.0.0:11434) that are valid for listeners, but invalid for requests. Listening on 0.0.0.0:11434 is valid, but curl http://0.0.0.0:11434 is invalid.

This probably only happens with OLLAMA_HOST="0.0.0.0:(any port)" Any other valid IP address would not have this problem. You could probably fix it with something like base_url = base_url.replace('0.0.0.0', '127.0.0.1') which would do the right thing and avoid this error (I'm not aware of any time that 0.0.0.0 would refer to a non-local listener, but I could be missing something).

Alternatively, you can fix it directly by setting OLLAMA_HOST before you import ollama

import os
os.environ["OLLAMA_HOST"] = "http://127.0.0.1:11434"  
import ollama
@bsharper commented on GitHub (Jun 19, 2025): I figured out the issue: `OLLAMA_HOST` tells the ollama server where to listen. However, there are addresses (like `0.0.0.0:11434`) that are valid for listeners, but invalid for requests. Listening on 0.0.0.0:11434 is valid, but `curl http://0.0.0.0:11434` is invalid. This probably only happens with `OLLAMA_HOST="0.0.0.0:(any port)"` Any other valid IP address would not have this problem. You could probably fix it with something like `base_url = base_url.replace('0.0.0.0', '127.0.0.1')` which would do the right thing and avoid this error (I'm not aware of any time that 0.0.0.0 would refer to a non-local listener, but I could be missing something). Alternatively, you can fix it directly by setting `OLLAMA_HOST` before you import `ollama` ``` import os os.environ["OLLAMA_HOST"] = "http://127.0.0.1:11434" import ollama ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ollama/ollama-python#50