Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```python
- # app/api/views.py
- class BaseModelView(views.MethodView):
- def __init__(self, request_model):
- self.request_model = request_model
- @classmethod
- def as_view(cls, name, *class_args, **class_kwargs):
- view = super().as_view(name, *class_args, **class_kwargs)
- view.model = cls(*class_args, **class_kwargs)
- return view
- class StreamItemsView(BaseModelView):
- async def get(self):
- if websocket.is_websocket():
- while True:
- await handle_stream_request(websocket, self.request_model)
- # app/api/items.py
- ideas_blueprint = Blueprint("ideas", __name__)
- ideas_blueprint.add_url_rule(
- "/generate", view_func=GenerateItemsView.as_view("generate_ideas", IdeaRequest)
- )
- ideas_blueprint.add_url_rule(
- "/stream",
- view_func=StreamItemsView.as_view("stream_ideas", IdeaRequest),
- is_websocket=True,
- )
- ```
- ```
- Traceback (most recent call last):
- File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\hypercorn\asyncio\task_group.py", line 23, in _handle
- await app(scope, receive, send, sync_spawn, call_soon)
- File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\hypercorn\app_wrappers.py", line 33, in __call__
- await self.app(scope, receive, send)
- File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\app.py", line 1902, in __call__
- await self.asgi_app(scope, receive, send)
- File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\app.py", line 1928, in asgi_app
- await asgi_handler(receive, send)
- File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\asgi.py", line 169, in __call__
- _raise_exceptions(done)
- File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\asgi.py", line 353, in _raise_exceptions
- raise task.exception()
- File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\asgi.py", line 207, in handle_websocket
- response = await self.app.handle_websocket(websocket)
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\app.py", line 1778, in handle_websocket
- return await self.handle_websocket_exception(error)
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\app.py", line 1146, in handle_websocket_exception
- raise error
- File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\app.py", line 1774, in handle_websocket
- return await self.full_dispatch_websocket(websocket_context)
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\app.py", line 1796, in full_dispatch_websocket
- result = await self.handle_user_exception(error)
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\app.py", line 1107, in handle_user_exception
- raise error
- File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\app.py", line 1794, in full_dispatch_websocket
- result = await self.dispatch_websocket(websocket_context)
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\app.py", line 1839, in dispatch_websocket
- return await self.ensure_async(handler)(**websocket_.view_args)
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\views.py", line 62, in view
- return await current_app.ensure_async(self.dispatch_request)(**kwargs)
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\views.py", line 122, in dispatch_request
- handler = getattr(self, request.method.lower(), None)
- ^^^^^^^^^^^^^^
- File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\werkzeug\local.py", line 311, in __get__
- obj = instance._get_current_object()
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\werkzeug\local.py", line 508, in _get_current_object
- raise RuntimeError(unbound_message) from None
- RuntimeError: Not within a request context
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement