Originally created by @ZipingL on GitHub (Dec 28, 2024).
Bug Report
Installation Method
I installed OpenWebUI using pip install within a Python 3.11 virtual environment created with Miniconda.
Environment
Open WebUI Version: [v0.3.11]
Ollama (if applicable): [N/A]
Operating System: Ubuntu 24.04
Browser (if applicable): N/A
Confirmation:
I have read and followed all the instructions provided in the README.md.
I am on the latest version of both Open WebUI and Ollama.
I have included the browser console logs (open-webui logs)
I have included the Docker container logs.
I have provided the exact steps to reproduce the bug in the "Steps to Reproduce" section below.
Expected Behavior:
When making an API request to /api/models with a valid API key using curl, the application should validate the API key and return the appropriate response without errors. The ENABLE_API_KEY_ENDPOINT_RESTRICTIONS attribute should be properly recognized by the application.
Actual Behavior:
When making an API request to /api/models with a valid API key in the Authorization header using curl, the application fails and raises the following error:
bash
AttributeError: 'State' object has no attribute 'ENABLE_API_KEY_ENDPOINT_RESTRICTIONS'
This issue occurs because the ENABLE_API_KEY_ENDPOINT_RESTRICTIONS attribute is not initialized in the application state (app.state). However, when accessing the same endpoint via a web browser, the error does not occur, and the endpoint functions as expected.
Description
Bug Summary:
The application attempts to access request.app.state.ENABLE_API_KEY_ENDPOINT_RESTRICTIONS during API requests made using curl, but this attribute is not initialized, resulting in an AttributeError. This issue does not occur when accessing the same endpoint via a web browser, leading to inconsistent behavior.
Reproduction Details
Steps to Reproduce:
Install OpenWebUI using pip in a Python 3.11 virtual environment.
Start the OpenWebUI server.
Enable "API Key Endpoint Restrictions" in the OpenWebUI settings.
Send a request to /api/models with a valid API key in the Authorization header using curl:
AttributeError: 'State' object has no attribute 'ENABLE_API_KEY_ENDPOINT_RESTRICTIONS'
Logs and Screenshots
Relevant Logs:
Traceback (most recent call last):
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 401, in run_asgi
result= await app(# type: ignore[func-returns-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__
return await self.app(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
await super().__call__(scope, receive, send)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
await self.middleware_stack(scope, receive, send)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
raise exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
await self.app(scope, receive, _send)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/cors.py", line 85, in __call__
await self.app(scope, receive, send)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
with collapse_excgroups():
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/contextlib.py", line 158, in __exit__
self.gen.throw(typ, value, traceback)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
raise exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 191, in __call__
response= await self.dispatch_func(request, call_next)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/open_webui/main.py", line 723, in inspect_websocket
return await call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 165, in call_next
raise app_exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
await self.app(scope, receive_or_disconnect, send_no_error)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
with collapse_excgroups():
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/contextlib.py", line 158, in __exit__
self.gen.throw(typ, value, traceback)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
raise exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 191, in __call__
response= await self.dispatch_func(request, call_next)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/open_webui/main.py", line 702, in check_url
response= await call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 165, in call_next
raise app_exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
await self.app(scope, receive_or_disconnect, send_no_error)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
with collapse_excgroups():
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/contextlib.py", line 158, in __exit__
self.gen.throw(typ, value, traceback)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
raise exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 191, in __call__
response= await self.dispatch_func(request, call_next)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/open_webui/main.py", line 692, in commit_session_after_request
response= await call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 165, in call_next
raise app_exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
await self.app(scope, receive_or_disconnect, send_no_error)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
with collapse_excgroups():
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/contextlib.py", line 158, in __exit__
self.gen.throw(typ, value, traceback)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
raise exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 191, in __call__
response= await self.dispatch_func(request, call_next)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/open_webui/utils/security_headers.py", line 11, in dispatch
response= await call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 165, in call_next
raise app_exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
await self.app(scope, receive_or_disconnect, send_no_error)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
with collapse_excgroups():
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/contextlib.py", line 158, in __exit__
self.gen.throw(typ, value, traceback)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
raise exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 191, in __call__
response= await self.dispatch_func(request, call_next)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/open_webui/main.py", line 681, in dispatch
response= await call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 165, in call_next
raise app_exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
await self.app(scope, receive_or_disconnect, send_no_error)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
raise exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/routing.py", line 756, in __call__
await self.middleware_stack(scope, receive, send)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/routing.py", line 776, in app
await route.handle(scope, receive, send)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/routing.py", line 297, in handle
await self.app(scope, receive, send)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/routing.py", line 77, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
raise exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/routing.py", line 72, in app
response= await func(request)
^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/fastapi/routing.py", line 269, in app
solved_result= await solve_dependencies(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/fastapi/dependencies/utils.py", line 572, in solve_dependencies
solved_result= await solve_dependencies(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/fastapi/dependencies/utils.py", line 602, in solve_dependencies
solved= await run_in_threadpool(call, **sub_values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/concurrency.py", line 42, in run_in_threadpool
return await anyio.to_thread.run_sync(func, *args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/anyio/to_thread.py", line 56, in run_sync
return await get_async_backend().run_sync_in_worker_thread(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 2505, in run_sync_in_worker_thread
return await future
^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 1005, in run
result= context.run(func, *args)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/open_webui/utils/auth.py", line 99, in get_current_user
if request.app.state.ENABLE_API_KEY_ENDPOINT_RESTRICTIONS:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/datastructures.py", line 702, in __getattr__
raise AttributeError(message.format(self.__class__.__name__, key))
AttributeError: 'State' object has no attribute 'ENABLE_API_KEY_ENDPOINT_RESTRICTIONS'
Originally created by @ZipingL on GitHub (Dec 28, 2024).
# Bug Report
## Installation Method
I installed OpenWebUI using `pip install` within a Python 3.11 virtual environment created with Miniconda.
## Environment
- **Open WebUI Version:** [v0.3.11]
- **Ollama (if applicable):** [N/A]
- **Operating System:** Ubuntu 24.04
- **Browser (if applicable):** N/A
**Confirmation:**
- [x] I have read and followed all the instructions provided in the README.md.
- [x] I am on the latest version of both Open WebUI and Ollama.
- [x] I have included the browser console logs (open-webui logs)
- [ ] I have included the Docker container logs.
- [x] I have provided the exact steps to reproduce the bug in the "Steps to Reproduce" section below.
## Expected Behavior:
When making an API request to `/api/models` with a valid API key using `curl`, the application should validate the API key and return the appropriate response without errors. The `ENABLE_API_KEY_ENDPOINT_RESTRICTIONS` attribute should be properly recognized by the application.
## Actual Behavior:
When making an API request to `/api/models` with a valid API key in the Authorization header using `curl`, the application fails and raises the following error:
bash
```
AttributeError: 'State' object has no attribute 'ENABLE_API_KEY_ENDPOINT_RESTRICTIONS'
```
This issue occurs because the `ENABLE_API_KEY_ENDPOINT_RESTRICTIONS` attribute is not initialized in the application state (`app.state`). However, when accessing the same endpoint via a web browser, the error does not occur, and the endpoint functions as expected.
## Description
**Bug Summary:**
The application attempts to access `request.app.state.ENABLE_API_KEY_ENDPOINT_RESTRICTIONS` during API requests made using `curl`, but this attribute is not initialized, resulting in an `AttributeError`. This issue does not occur when accessing the same endpoint via a web browser, leading to inconsistent behavior.
## Reproduction Details
**Steps to Reproduce:**
1. Install OpenWebUI using pip in a Python 3.11 virtual environment.
2. Start the OpenWebUI server.
3. Enable "API Key Endpoint Restrictions" in the OpenWebUI settings.
4. Send a request to `/api/models` with a valid API key in the `Authorization` header using `curl`:
```bash
curl -H "Authorization: Bearer <valid_api_key>" https://your_openwebui_server/api/models
```
5. Observe the following error in the logs:
```
AttributeError: 'State' object has no attribute 'ENABLE_API_KEY_ENDPOINT_RESTRICTIONS'
```
## Logs and Screenshots
**Relevant Logs:**
```bash
Traceback (most recent call last):
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 401, in run_asgi
result = await app( # type: ignore[func-returns-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__
return await self.app(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
await super().__call__(scope, receive, send)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
await self.middleware_stack(scope, receive, send)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
raise exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
await self.app(scope, receive, _send)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/cors.py", line 85, in __call__
await self.app(scope, receive, send)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
with collapse_excgroups():
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/contextlib.py", line 158, in __exit__
self.gen.throw(typ, value, traceback)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
raise exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 191, in __call__
response = await self.dispatch_func(request, call_next)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/open_webui/main.py", line 723, in inspect_websocket
return await call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 165, in call_next
raise app_exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
await self.app(scope, receive_or_disconnect, send_no_error)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
with collapse_excgroups():
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/contextlib.py", line 158, in __exit__
self.gen.throw(typ, value, traceback)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
raise exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 191, in __call__
response = await self.dispatch_func(request, call_next)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/open_webui/main.py", line 702, in check_url
response = await call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 165, in call_next
raise app_exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
await self.app(scope, receive_or_disconnect, send_no_error)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
with collapse_excgroups():
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/contextlib.py", line 158, in __exit__
self.gen.throw(typ, value, traceback)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
raise exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 191, in __call__
response = await self.dispatch_func(request, call_next)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/open_webui/main.py", line 692, in commit_session_after_request
response = await call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 165, in call_next
raise app_exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
await self.app(scope, receive_or_disconnect, send_no_error)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
with collapse_excgroups():
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/contextlib.py", line 158, in __exit__
self.gen.throw(typ, value, traceback)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
raise exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 191, in __call__
response = await self.dispatch_func(request, call_next)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/open_webui/utils/security_headers.py", line 11, in dispatch
response = await call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 165, in call_next
raise app_exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
await self.app(scope, receive_or_disconnect, send_no_error)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
with collapse_excgroups():
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/contextlib.py", line 158, in __exit__
self.gen.throw(typ, value, traceback)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
raise exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 191, in __call__
response = await self.dispatch_func(request, call_next)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/open_webui/main.py", line 681, in dispatch
response = await call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 165, in call_next
raise app_exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
await self.app(scope, receive_or_disconnect, send_no_error)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
raise exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/routing.py", line 756, in __call__
await self.middleware_stack(scope, receive, send)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/routing.py", line 776, in app
await route.handle(scope, receive, send)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/routing.py", line 297, in handle
await self.app(scope, receive, send)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/routing.py", line 77, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
raise exc
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/routing.py", line 72, in app
response = await func(request)
^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/fastapi/routing.py", line 269, in app
solved_result = await solve_dependencies(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/fastapi/dependencies/utils.py", line 572, in solve_dependencies
solved_result = await solve_dependencies(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/fastapi/dependencies/utils.py", line 602, in solve_dependencies
solved = await run_in_threadpool(call, **sub_values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/concurrency.py", line 42, in run_in_threadpool
return await anyio.to_thread.run_sync(func, *args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/anyio/to_thread.py", line 56, in run_sync
return await get_async_backend().run_sync_in_worker_thread(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 2505, in run_sync_in_worker_thread
return await future
^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 1005, in run
result = context.run(func, *args)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/open_webui/utils/auth.py", line 99, in get_current_user
if request.app.state.ENABLE_API_KEY_ENDPOINT_RESTRICTIONS:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/suntzuping/miniconda3/envs/open-webui/lib/python3.11/site-packages/starlette/datastructures.py", line 702, in __getattr__
raise AttributeError(message.format(self.__class__.__name__, key))
AttributeError: 'State' object has no attribute 'ENABLE_API_KEY_ENDPOINT_RESTRICTIONS'
```
**Screenshots/Screen Recordings (if applicable):**
N/A
## Additional Information
**Suggested Fix:**
The issue can be resolved by:
1. Using `getattr` to handle the missing attribute gracefully in `auth.py at line 99`:
```python
if getattr(request.app.state, "ENABLE_API_KEY_ENDPOINT_RESTRICTIONS", False):
```
**Environment Details:**
- Python 3.11
- Miniconda virtual environment
- Running as a systemd service
- Endpoint tested: `/api/models`
99386bf Already fixed in dev, so, hope that 0.5.3 is coming soon
Cool beans
@ZipingL commented on GitHub (Dec 28, 2024):
> [99386bf](https://github.com/open-webui/open-webui/commit/99386bf680fc3278fd25c54ba7e02d0b50a470b3) Already fixed in dev, so, hope that 0.5.3 is coming soon
Cool beans
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @ZipingL on GitHub (Dec 28, 2024).
Bug Report
Installation Method
I installed OpenWebUI using
pip installwithin a Python 3.11 virtual environment created with Miniconda.Environment
Open WebUI Version: [v0.3.11]
Ollama (if applicable): [N/A]
Operating System: Ubuntu 24.04
Browser (if applicable): N/A
Confirmation:
Expected Behavior:
When making an API request to
/api/modelswith a valid API key usingcurl, the application should validate the API key and return the appropriate response without errors. TheENABLE_API_KEY_ENDPOINT_RESTRICTIONSattribute should be properly recognized by the application.Actual Behavior:
When making an API request to
/api/modelswith a valid API key in the Authorization header usingcurl, the application fails and raises the following error:bash
This issue occurs because the
ENABLE_API_KEY_ENDPOINT_RESTRICTIONSattribute is not initialized in the application state (app.state). However, when accessing the same endpoint via a web browser, the error does not occur, and the endpoint functions as expected.Description
Bug Summary:
The application attempts to access
request.app.state.ENABLE_API_KEY_ENDPOINT_RESTRICTIONSduring API requests made usingcurl, but this attribute is not initialized, resulting in anAttributeError. This issue does not occur when accessing the same endpoint via a web browser, leading to inconsistent behavior.Reproduction Details
Steps to Reproduce:
/api/modelswith a valid API key in theAuthorizationheader usingcurl:Logs and Screenshots
Relevant Logs:
Screenshots/Screen Recordings (if applicable):
N/A
Additional Information
Suggested Fix:
The issue can be resolved by:
Using
getattrto handle the missing attribute gracefully inauth.py at line 99:Environment Details:
/api/models@tjbck commented on GitHub (Dec 28, 2024):
#8135
@ZipingL commented on GitHub (Dec 28, 2024):
Cool beans