AttributeError: 'RequestHandler' object has no attribute 'user' #23

Closed
opened 2025-07-08 08:36:52 -04:00 by AtHeartEngineer · 0 comments

Originally created by @changchiyou on 2/20/2024

config.ini

[DefaultServer]
url = http://localhost:11434
queue_size = 3

commend

ollama_proxy_server --port 8080 -d

Error Log

Starting server
Running server on port 8080
192.168.110.5 - - [20/Feb/2024 17:02:12] "GET /api/tags HTTP/1.1" - -
192.168.110.5 - - [20/Feb/2024 17:02:12] "GET /api/tags HTTP/1.1" 200 -
192.168.110.5 - - [20/Feb/2024 17:02:15] "GET /api/version HTTP/1.1" - -
192.168.110.5 - - [20/Feb/2024 17:02:15] "GET /api/version HTTP/1.1" 200 -
192.168.110.5 - - [20/Feb/2024 17:02:18] "POST /api/chat HTTP/1.1" - -
----------------------------------------
Exception occurred during processing of request from ('192.168.110.5', 62516)
Traceback (most recent call last):
  File "/home/fvt/miniconda3/envs/llm/lib/python3.11/socketserver.py", line 691, in process_request_thread
    self.finish_request(request, client_address)
  File "/home/fvt/miniconda3/envs/llm/lib/python3.11/socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/home/fvt/miniconda3/envs/llm/lib/python3.11/socketserver.py", line 755, in __init__
    self.handle()
  File "/home/fvt/miniconda3/envs/llm/lib/python3.11/http/server.py", line 431, in handle
    self.handle_one_request()
  File "/home/fvt/miniconda3/envs/llm/lib/python3.11/http/server.py", line 419, in handle_one_request
    method()
  File "/home/fvt/Desktop/Code/ollama_proxy_server/ollama_proxy_server/main.py", line 86, in do_POST
    self.proxy()
  File "/home/fvt/Desktop/Code/ollama_proxy_server/ollama_proxy_server/main.py", line 145, in proxy
    self.add_access_log_entry(event="gen_request", user=self.user, ip_address=client_ip, access="Authorized", server=min_queued_server[0], nb_queued_requests_on_server=que.qsize())
                                                        ^^^^^^^^^
AttributeError: 'RequestHandler' object has no attribute 'user'

My Research

c6aee7e671/ollama_proxy_server/main.py (L108)

The if-logic above is incorrect, because self._validate_user_and_key() would not be execute while the first expression not deactivate_security is not True.

I fix the problem via assign initial value to self.user:

def proxy(self):
+ self.user = "unknown"
  if not deactivate_security and not self._validate_user_and_key():
*Originally created by @changchiyou on 2/20/2024* ### `config.ini` ``` [DefaultServer] url = http://localhost:11434 queue_size = 3 ``` ### commend ``` ollama_proxy_server --port 8080 -d ``` ### Error Log ``` Starting server Running server on port 8080 192.168.110.5 - - [20/Feb/2024 17:02:12] "GET /api/tags HTTP/1.1" - - 192.168.110.5 - - [20/Feb/2024 17:02:12] "GET /api/tags HTTP/1.1" 200 - 192.168.110.5 - - [20/Feb/2024 17:02:15] "GET /api/version HTTP/1.1" - - 192.168.110.5 - - [20/Feb/2024 17:02:15] "GET /api/version HTTP/1.1" 200 - 192.168.110.5 - - [20/Feb/2024 17:02:18] "POST /api/chat HTTP/1.1" - - ---------------------------------------- Exception occurred during processing of request from ('192.168.110.5', 62516) Traceback (most recent call last): File "/home/fvt/miniconda3/envs/llm/lib/python3.11/socketserver.py", line 691, in process_request_thread self.finish_request(request, client_address) File "/home/fvt/miniconda3/envs/llm/lib/python3.11/socketserver.py", line 361, in finish_request self.RequestHandlerClass(request, client_address, self) File "/home/fvt/miniconda3/envs/llm/lib/python3.11/socketserver.py", line 755, in __init__ self.handle() File "/home/fvt/miniconda3/envs/llm/lib/python3.11/http/server.py", line 431, in handle self.handle_one_request() File "/home/fvt/miniconda3/envs/llm/lib/python3.11/http/server.py", line 419, in handle_one_request method() File "/home/fvt/Desktop/Code/ollama_proxy_server/ollama_proxy_server/main.py", line 86, in do_POST self.proxy() File "/home/fvt/Desktop/Code/ollama_proxy_server/ollama_proxy_server/main.py", line 145, in proxy self.add_access_log_entry(event="gen_request", user=self.user, ip_address=client_ip, access="Authorized", server=min_queued_server[0], nb_queued_requests_on_server=que.qsize()) ^^^^^^^^^ AttributeError: 'RequestHandler' object has no attribute 'user' ``` ### My Research https://github.com/ParisNeo/ollama_proxy_server/blob/c6aee7e67139d6ad04ff164f286335377dd9fbdc/ollama_proxy_server/main.py#L108 The if-logic above is incorrect, because `self._validate_user_and_key()` would not be execute while the first expression `not deactivate_security` is not `True`. I fix the problem via assign initial value to `self.user`: ```diff def proxy(self): + self.user = "unknown" if not deactivate_security and not self._validate_user_and_key(): ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/ollama_proxy_server#23