mirror of
https://github.com/ollama/ollama-python.git
synced 2026-07-21 09:05:23 -04:00
Unable to Connect to Localhost by Default When OLLAMA_HOST is Set to 0.0.0.0 #198
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Tryanks on GitHub (Jan 5, 2025).
I set the environment variable OLLAMA_HOST to 0.0.0.0:11434, allowing it to serve the local network. At the same time, I am running some local applications written in Python on the same machine. I noticed that I cannot directly use
from ollama import chat; instead, I must first specifyclient = Client("http://localhost:11434")before I can useclient.chat.I suspect this is because the ollama-python library also reads the OLLAMA_HOST environment variable and uses it as the default access address.
A possible fix would be to add a special case for handling 0.0.0.0 in the
_parse_hostmethod.@lzu-tangym commented on GitHub (Feb 13, 2025):
i have the same question, do you find the solution ?
@Tryanks commented on GitHub (Feb 13, 2025):
I don't know why this issue is not being considered as something that needs to be resolved. If possible, I would like to hear the thoughts of the main maintainer :(
To fix it, you can handle the captured values at the following two links to include the special case of 0.0.0.0:
https://github.com/ollama/ollama-python/blob/0561f427011cf93e65f3f4b0de60d814cc7a754a/ollama/_client.py#L92
https://github.com/ollama/ollama-python/blob/0561f427011cf93e65f3f4b0de60d814cc7a754a/ollama/_client.py#L1155
After making the changes, feel free to submit a pull request to the main repository to include this fix (if it constitutes a bug).
@lzu-tangym commented on GitHub (Feb 13, 2025):
sorry, i can not understand how to fix it, can you show me more directly? besides, i try that langchain_ollama, chatollama(model) or ollamaembeddings(model), error "can not connect to ollama " appear! do you find that question?
@lzu-tangym commented on GitHub (Feb 13, 2025):
could you help more directly, i do not understand your solution, thank you sincerely!
@Tryanks commented on GitHub (Feb 13, 2025):
If you do not want to contribute to this repository, the only way to solve this problem is to specify
localhostas the URL. No further prompting, sorry : (@lzu-tangym commented on GitHub (Feb 13, 2025):
thank you very much, i think it is bug maybe? or our host not set correctly? hope someone else join us chat
@YANG-Haruka commented on GitHub (Feb 17, 2025):
Yes I also find the same problem.
IF we set OLLAMA_HOST=0.0.0.0:11434,
ollama.list command will also not use. 😔
@ParthSareen commented on GitHub (Apr 9, 2025):
This is expected behavior - probably surfaced with the httpx bump from a bit ago.
OLLAMA_HOSTshould not be0.0.0.0from the client side. It should be set to where your instance is or127.0.0.1:11434if localSee:
https://github.com/ollama/ollama-python/pull/491#issuecomment-2790636938
@Tryanks commented on GitHub (Apr 9, 2025):
Setting OLLAMA_HOST to 0.0.0.0 is because it applies to the server side. In most cases involved in this topic, the client side and the server side run on the same computer.
If in such cases, the client side cannot access the local server side via
0.0.0.0:11434, it may be a BUG.@ktos commented on GitHub (Apr 11, 2025):
Yes. I have ollama running on my machine and I want it to be available to other machines in my network. And on the same machine ("server") I want to use ollama client libraries.
Even more: I am using Windows where there is no easy way to set different set of environment variables for different processes, especially if Ollama is installing itself and running automatically.
Using same env variable for both client and server configuration is, in this case, the source of the issue :/