Advertisement
drinfernoo

Untitled

May 19th, 2023
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. ```python
  2. # app/api/views.py
  3. class BaseModelView(views.MethodView):
  4. def __init__(self, request_model):
  5. self.request_model = request_model
  6.  
  7. @classmethod
  8. def as_view(cls, name, *class_args, **class_kwargs):
  9. view = super().as_view(name, *class_args, **class_kwargs)
  10. view.model = cls(*class_args, **class_kwargs)
  11. return view
  12.  
  13. class StreamItemsView(BaseModelView):
  14. async def get(self):
  15. if websocket.is_websocket():
  16. while True:
  17. await handle_stream_request(websocket, self.request_model)
  18.  
  19. # app/api/items.py
  20. ideas_blueprint = Blueprint("ideas", __name__)
  21.  
  22. ideas_blueprint.add_url_rule(
  23. "/generate", view_func=GenerateItemsView.as_view("generate_ideas", IdeaRequest)
  24. )
  25. ideas_blueprint.add_url_rule(
  26. "/stream",
  27. view_func=StreamItemsView.as_view("stream_ideas", IdeaRequest),
  28. is_websocket=True,
  29. )
  30. ```
  31.  
  32. ```
  33. Traceback (most recent call last):
  34. File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\hypercorn\asyncio\task_group.py", line 23, in _handle
  35. await app(scope, receive, send, sync_spawn, call_soon)
  36. File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\hypercorn\app_wrappers.py", line 33, in __call__
  37. await self.app(scope, receive, send)
  38. File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\app.py", line 1902, in __call__
  39. await self.asgi_app(scope, receive, send)
  40. File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\app.py", line 1928, in asgi_app
  41. await asgi_handler(receive, send)
  42. File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\asgi.py", line 169, in __call__
  43. _raise_exceptions(done)
  44. File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\asgi.py", line 353, in _raise_exceptions
  45. raise task.exception()
  46. File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\asgi.py", line 207, in handle_websocket
  47. response = await self.app.handle_websocket(websocket)
  48. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  49. File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\app.py", line 1778, in handle_websocket
  50. return await self.handle_websocket_exception(error)
  51. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  52. File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\app.py", line 1146, in handle_websocket_exception
  53. raise error
  54. File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\app.py", line 1774, in handle_websocket
  55. return await self.full_dispatch_websocket(websocket_context)
  56. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  57. File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\app.py", line 1796, in full_dispatch_websocket
  58. result = await self.handle_user_exception(error)
  59. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  60. File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\app.py", line 1107, in handle_user_exception
  61. raise error
  62. File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\app.py", line 1794, in full_dispatch_websocket
  63. result = await self.dispatch_websocket(websocket_context)
  64. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  65. File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\app.py", line 1839, in dispatch_websocket
  66. return await self.ensure_async(handler)(**websocket_.view_args)
  67. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  68. File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\views.py", line 62, in view
  69. return await current_app.ensure_async(self.dispatch_request)(**kwargs)
  70. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  71. File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\quart\views.py", line 122, in dispatch_request
  72. handler = getattr(self, request.method.lower(), None)
  73. ^^^^^^^^^^^^^^
  74. File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\werkzeug\local.py", line 311, in __get__
  75. obj = instance._get_current_object()
  76. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  77. File "C:\Users\drinf\Documents\GitHub\BeddyBai\.venv\Lib\site-packages\werkzeug\local.py", line 508, in _get_current_object
  78. raise RuntimeError(unbound_message) from None
  79. RuntimeError: Not within a request context
  80. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement