Running without network error: ollama._types.ResponseError #46

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

Originally created by @Gloridust on GitHub (Mar 8, 2024).

Really helpful project! However, I met some problem When I turn off WI-FI connection.

  • OS: Windows10 LTSC
  • cpu: R7-7840H
  • Language: Python
Traceback (most recent call last):
  File "c:\Users\gloridust\Documents\GitHub\LocalChatLLM\start.py", line 117, in <module>
    main_loop()
  File "c:\Users\gloridust\Documents\GitHub\LocalChatLLM\start.py", line 99, in main_loop
    output_text, received_message = get_response(message_history)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\gloridust\Documents\GitHub\LocalChatLLM\start.py", line 63, in get_response
    response = ollama.chat(
               ^^^^^^^^^^^^
  File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\ollama\_client.py", line 177, in chat        
    return self._request_stream(
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\ollama\_client.py", line 97, in _request_stream
    return self._stream(*args, **kwargs) if stream else self._request(*args, **kwargs).json()
                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\ollama\_client.py", line 73, in _request     
    raise ResponseError(e.response.text, e.response.status_code) from None
ollama._types.ResponseError

All of my program can work well with internet connection. But when I turn off the wifi switch, it totally error.
U can see my project at:https://github.com/Gloridust/LocalChatLLM
I really need it to run completely offline, any solutions?

Originally created by @Gloridust on GitHub (Mar 8, 2024). Really helpful project! However, I met some problem When I turn off WI-FI connection. - OS: Windows10 LTSC - cpu: R7-7840H - Language: Python ``` Traceback (most recent call last): File "c:\Users\gloridust\Documents\GitHub\LocalChatLLM\start.py", line 117, in <module> main_loop() File "c:\Users\gloridust\Documents\GitHub\LocalChatLLM\start.py", line 99, in main_loop output_text, received_message = get_response(message_history) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "c:\Users\gloridust\Documents\GitHub\LocalChatLLM\start.py", line 63, in get_response response = ollama.chat( ^^^^^^^^^^^^ File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\ollama\_client.py", line 177, in chat return self._request_stream( ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\ollama\_client.py", line 97, in _request_stream return self._stream(*args, **kwargs) if stream else self._request(*args, **kwargs).json() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\ollama\_client.py", line 73, in _request raise ResponseError(e.response.text, e.response.status_code) from None ollama._types.ResponseError ``` All of my program can work well with internet connection. But when I turn off the wifi switch, it totally error. U can see my project at:https://github.com/Gloridust/LocalChatLLM I really need it to run completely offline, any solutions?
Author
Owner

@hj199717 commented on GitHub (Mar 31, 2024):

遇到同样的问题了,只要网络不通就报这个错,您这边解决这个问题了吗。
可以尝试下openai的API看行不行:

from openai import OpenAI
client = OpenAI(
base_url='http://localhost:11434/v1/',
api_key='ollama', # required but ignored
)
chat_completion = client.chat.completions.create(
messages=[
{
'role': 'user',
'content': 'Say this is a test',
}
],
model='qwen:4b',
)

@hj199717 commented on GitHub (Mar 31, 2024): 遇到同样的问题了,只要网络不通就报这个错,您这边解决这个问题了吗。 可以尝试下openai的API看行不行: from openai import OpenAI client = OpenAI( base_url='http://localhost:11434/v1/', api_key='ollama', # required but ignored ) chat_completion = client.chat.completions.create( messages=[ { 'role': 'user', 'content': 'Say this is a test', } ], model='qwen:4b', )
Author
Owner

@Gloridust commented on GitHub (Apr 3, 2024):

仍然有一些问题。
首先这个openai的接口在输出格式上有一些问题,直接'print(chat_completion),你会发现输出格式如下:
There are still some issues.
First of all, this openai interface has some problems with the output format. Directly 'print(chat_completion)', you will find that the output format is as follows:

ChatCompletion(id='chatcmpl-969', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='Sure, 
I can say "This is a test" as required. Is there anything else you would like me to do in this context?\n', role='assistant', function_call=N(completion_tokens=31, prompt_tokens=0, total_tokens=31))

然后我做出了些许修改:
Then I made some changes:

print(chat_completion.choices[0].message.content)

至此,在联网状况下正常运行,但是一旦断开网络链接,就出现了更多问题:
At this point, it runs normally when connected to the Internet, but once the network connection is disconnected, more problems occur:

Traceback (most recent call last):
  File "c:\Users\gloridust\Documents\GitHub\LocalChatLLM\test\test_openai-API.py", line 8, in <module>
    chat_completion = client.chat.completions.create(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_utils\_utils.py", line 275, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\resources\chat\completions.py", line 667, in create
    return self._post(
           ^^^^^^^^^^^
  File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_base_client.py", line 1213, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_base_client.py", line 902, in request
    return self._request(
           ^^^^^^^^^^^^^^
  File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_base_client.py", line 978, in _request
    return self._retry_request(
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_base_client.py", line 1026, in _retry_request   
    return self._request(
           ^^^^^^^^^^^^^^
  File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_base_client.py", line 978, in _request
    return self._retry_request(
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_base_client.py", line 1026, in _retry_request   
    return self._request(
           ^^^^^^^^^^^^^^
  File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_base_client.py", line 993, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.InternalServerError: Error code: 502

貌似是OpenAI的接口需要联网。在创建chat completion时出现了内部服务器错误(Error code: 502)。这意味着在尝试与OpenAI服务器通信时出现了问题。
It seems that the OpenAI interface needs to be connected to the Internet. An internal server error occurred while creating the chat completion (Error code: 502). This means there is a problem while trying to communicate with the OpenAI server.

@Gloridust commented on GitHub (Apr 3, 2024): 仍然有一些问题。 首先这个openai的接口在输出格式上有一些问题,直接'print(chat_completion),你会发现输出格式如下: There are still some issues. First of all, this openai interface has some problems with the output format. Directly 'print(chat_completion)', you will find that the output format is as follows: ``` ChatCompletion(id='chatcmpl-969', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='Sure, I can say "This is a test" as required. Is there anything else you would like me to do in this context?\n', role='assistant', function_call=N(completion_tokens=31, prompt_tokens=0, total_tokens=31)) ``` 然后我做出了些许修改: Then I made some changes: ``` print(chat_completion.choices[0].message.content) ``` 至此,在联网状况下正常运行,但是一旦断开网络链接,就出现了更多问题: At this point, it runs normally when connected to the Internet, but once the network connection is disconnected, more problems occur: ``` Traceback (most recent call last): File "c:\Users\gloridust\Documents\GitHub\LocalChatLLM\test\test_openai-API.py", line 8, in <module> chat_completion = client.chat.completions.create( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_utils\_utils.py", line 275, in wrapper return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\resources\chat\completions.py", line 667, in create return self._post( ^^^^^^^^^^^ File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_base_client.py", line 1213, in post return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_base_client.py", line 902, in request return self._request( ^^^^^^^^^^^^^^ File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_base_client.py", line 978, in _request return self._retry_request( ^^^^^^^^^^^^^^^^^^^^ File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_base_client.py", line 1026, in _retry_request return self._request( ^^^^^^^^^^^^^^ File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_base_client.py", line 978, in _request return self._retry_request( ^^^^^^^^^^^^^^^^^^^^ File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_base_client.py", line 1026, in _retry_request return self._request( ^^^^^^^^^^^^^^ File "C:\Users\gloridust\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_base_client.py", line 993, in _request raise self._make_status_error_from_response(err.response) from None openai.InternalServerError: Error code: 502 ``` 貌似是OpenAI的接口需要联网。在创建chat completion时出现了内部服务器错误(Error code: 502)。这意味着在尝试与OpenAI服务器通信时出现了问题。 It seems that the OpenAI interface needs to be connected to the Internet. An internal server error occurred while creating the chat completion (Error code: 502). This means there is a problem while trying to communicate with the OpenAI server.
Author
Owner

@likw99 commented on GitHub (Aug 2, 2024):

Met similar issue that direct me here, fixed by turning off the global proxy.
Tried turning off the wifi, and it still works (on MacOS).

@likw99 commented on GitHub (Aug 2, 2024): Met similar issue that direct me here, fixed by turning off the global proxy. Tried turning off the wifi, and it still works (on MacOS).
Author
Owner

@rymquym commented on GitHub (Aug 8, 2024):

be sure if running offline to use ollama serve

@rymquym commented on GitHub (Aug 8, 2024): be sure if running offline to use ollama serve
Author
Owner

@aopstudio commented on GitHub (Oct 14, 2024):

Met similar issue that direct me here, fixed by turning off the global proxy. Tried turning off the wifi, and it still works (on MacOS).

It works for me. Thanks!

@aopstudio commented on GitHub (Oct 14, 2024): > Met similar issue that direct me here, fixed by turning off the global proxy. Tried turning off the wifi, and it still works (on MacOS). It works for me. Thanks!
Author
Owner

@immmor commented on GitHub (Jan 2, 2025):

be sure if running offline to use ollama serve
But I want to use ollama serve with wifi. Do you know how to fix that?

@immmor commented on GitHub (Jan 2, 2025): > be sure if running offline to use ollama serve But I want to use ollama serve with wifi. Do you know how to fix that?
Author
Owner

@xzyJJboom commented on GitHub (Jan 20, 2025):

Met similar issue that direct me here, fixed by turning off the global proxy. Tried turning off the wifi, and it still works (on MacOS).

It works for me. Thanks! Until now, I used the Intranet to penetrate the tunnel

@xzyJJboom commented on GitHub (Jan 20, 2025): > Met similar issue that direct me here, fixed by turning off the global proxy. Tried turning off the wifi, and it still works (on MacOS). It works for me. Thanks! Until now, I used the Intranet to penetrate the tunnel
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ollama/ollama-python#46