Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Phil Jones
    @pgjones
    @the-infinity it should do (bug if it doesn't)
    shantanoo
    @shantanoo:matrix.org
    [m]
    hi, how do i use sqlite3 or ORM like peewee (sqlite3) with quart?
    was looking @ https://aiosqlite.omnilib.dev/en/stable/ but couldn't find any example
    Phil Jones
    @pgjones
    Hi @shantanoo:matrix.org there isn't anything particularly special you need to do. Which aspects are you unsure about? Here is an sqlite example and pgjones/quart#35 is a good discussion.
    5 replies
    Montassar Ben Dhifallah
    @Momentum-TN
    hello everyone,
    I am new to quart.
    I want to get multiple files from a request. In flask, I used to use request.files.getlist("file")
    What is the equivalent in quart ?
    Phil Jones
    @pgjones
    (await request.files).getlist("file") should work
    shantanoo
    @shantanoo:matrix.org
    [m]
    but asyncpg seems nice
    Montassar Ben Dhifallah
    @Momentum-TN
    @pgjones thank you so much !
    tomgper
    @tomgper
    hi, I'm moving some code from flask to quart. In flask with gevent we had a way to obtain the port that was opened by the internal socket (configured with port 0 basically). Is there a way to do the same with quart (asyncio) + hypercorn? Thank you
    Montassar Ben Dhifallah
    @Momentum-TN

    hey everyone!
    hope you are all well
    I am trying to learn how to make an ML-based web app using Quart.
    I want to build an application that can handle prediction of a batch of images. I want to divide the batch into small chunks, make predictions and return the response to the user. This process should be done until the last chunk
    I thought of making an async recursive api call. All I want to do is to make it recursively return the response.

    Any help is appreciated.
    This is the function that I want to call it recursively.

    @app.route('/predict', methods=['POST'])
    async def predict():
    
        if request.method == 'POST':
            has_files = (await request.files).get("file", None)
        if has_files:
            files = (await request.files).getlist("file")
            responses= {}
            # split files into small chunks to place here !
    
            for file, i in zip(files, range(len(files))):
                img_bytes = file.read()
    
                class_id, class_name = await get_prediction(model=model,
                                                      image_bytes=img_bytes,
                                                      imagenet_class_index= imagenet_class_index)
                responses[i] = {'class_id': class_id, 'class_name': class_name}
                print(responses[i])
    
            return await render_template("results.html", text=str(responses))
        else:
            return await render_template("results.html", text="please upload image!")
    Phil Jones
    @pgjones
    Would something using Server Sent Events, SSE, be what you need? https://gitlab.com/pgjones/quart/-/tree/master/examples/broadcast
    Ahmad Kurdi
    @ahmaddmkurdii_twitter
    Hello, I would like to ask how can I make my Quart API await for API Calls before opening new connections? Cause every time a request is sent to the Quart app, it processes it and opens a new connection after it's done automatically, even if there is no API calls which leads to timeout after 60s. Thank you.
    I have previously opened a GitLab issue: pgjones/quart#409
    Phil Jones
    @pgjones
    I've responded, but I don't fully understand what the issue is
    luna
    @lun-4

    @pgjones when using websocket.close() from latest quart (from master branch), i get an error because quart is trying to close the websocket again in handle_websocket

    I made a hotfix for hypercorn that forces only one websocket.close event to be executed, ignoring the rest. I did this in hypercorn because quart is not aware of the websocket state, and so it can not know if the websocket has closed (or is in the process of doing so), does this make sense? Is it correct to MR this fix?

    Another question: Is hypercorn going to support HTTP&Websockets ASGI 2.3? reason is not a blocker on my webapp development, but it is wanted in the future (this would also mean support for 2.2, since hypercorn is currently on 2.1)

    fiatjaf
    @fiatjaf
    whenever there is any error or exception anywhere in my app, quart just stops working -- but it doesn't crash.
    trio's nurseries break and stop accepting tasks, HTTP requests time out without logging anything to the server
    and so on
    what am I doing wrong?
    I imagine there is a way to catch all exceptions by default and show them to the user and go on
    this is the code (if it matters, probably not): https://github.com/lnbits/lnbits
    Phil Jones
    @pgjones
    @lun-4 I think that is a good solution, but I'll check pgjones/quart#410.
    Yep, Hypercorn will support 2.3 when I next release it
    luna
    @lun-4
    Thank you!
    Phil Jones
    @pgjones
    @fiatjaf is there a traceback you can share?
    fiatjaf
    @fiatjaf
    hypercorn[497166]: [2021-05-03 18:07:08 +0000] [497166] [ERROR] Error in ASGI Framework
    hypercorn[497166]: Traceback (most recent call last):
    hypercorn[497166]:   File "/root/lnbits/venv/lib/python3.8/site-packages/hypercorn/trio/context.py", line 39, in _handle
    hypercorn[497166]:     await invoke_asgi(app, scope, receive, send)
    hypercorn[497166]:   File "/root/lnbits/venv/lib/python3.8/site-packages/hypercorn/utils.py", line 239, in invoke_asgi
    hypercorn[497166]:     await app(scope, receive, send)
    hypercorn[497166]:   File "/root/lnbits/venv/lib/python3.8/site-packages/quart/app.py", line 2117, in __call__
    hypercorn[497166]:     await self.asgi_app(scope, receive, send)
    hypercorn[497166]:   File "/root/lnbits/venv/lib/python3.8/site-packages/quart/app.py", line 2140, in asgi_app
    hypercorn[497166]:     await asgi_handler(receive, send)
    hypercorn[497166]:   File "/root/lnbits/venv/lib/python3.8/site-packages/quart_trio/asgi.py", line 18, in __call__
    hypercorn[497166]:     nursery.start_soon(self.handle_request, nursery, request, send)
    hypercorn[497166]:   File "/root/lnbits/venv/lib/python3.8/site-packages/trio/_core/_run.py", line 741, in __aexit__
    hypercorn[497166]:     raise combined_error_from_nursery
    hypercorn[497166]:   File "/root/lnbits/venv/lib/python3.8/site-packages/quart_trio/asgi.py", line 29, in handle_request
    hypercorn[497166]:     response = await self.app.handle_request(request)
    hypercorn[497166]:   File "/root/lnbits/venv/lib/python3.8/site-packages/quart_trio/app.py", line 135, in handle_request
    hypercorn[497166]:     return await self.handle_exception(error)
    hypercorn[497166]:   File "/root/lnbits/venv/lib/python3.8/site-packages/quart/app.py", line 1118, in handle_exception
    hypercorn[497166]:     raise error
    hypercorn[497166]:   File "/root/lnbits/venv/lib/python3.8/site-packages/quart_trio/app.py", line 131, in handle_request
    hypercorn[497166]:     return await self.full_dispatch_request(request_context)
    hypercorn[497166]:   File "/root/lnbits/venv/lib/python3.8/site-packages/quart_trio/app.py", line 153, in full_dispatch_request
    hypercorn[497166]:     result = await self.handle_user_exception(error)
    hypercorn[497166]:   File "/root/lnbits/venv/lib/python3.8/site-packages/quart_trio/app.py", line 166, in handle_user_exception
    hypercorn[497166]:     return await super().handle_user_exception(error)
    hypercorn[497166]:   File "/root/lnbits/venv/lib/python3.8/site-packages/quart/app.py", line 1104, in handle_user_exception
    hypercorn[497166]:     raise error
    hypercorn[497166]:   File "/root/lnbits/venv/lib/python3.8/site-packages/quart_trio/app.py", line 151, in full_dispatch_request
    hypercorn[497166]:     result = await self.dispatch_request(request_context)
    hypercorn[497166]:   File "/root/lnbits/venv/lib/python3.8/site-packages/quart/app.py", line 1933, in dispatch_request
    hypercorn[497166]:     return await handler(**request_.view_args)
    hypercorn[497166]:   File "/root/lnbits/lnbits/decorators.py", line 28, in wrapped_view
    hypercorn[497166]:     return await view(**kwargs)
    hypercorn[497166]:   File "/root/lnbits/lnbits/core/views/api.py", line 313, in api_payments_sse
    hypercorn[497166]:     g.nursery.start_soon(payment_received)
    hypercorn[497166]:   File "/root/lnbits/venv/lib/python3.8/site-packages/trio/_core/_run.py", line 912, in start_soon
    hypercorn[497166]:     GLOBAL_RUN_CONTEXT.runner.spawn_impl(async_fn, args, self, name)
    hypercorn[497166]:   File "/root/lnbits/venv/lib/python3.8/site-packages/trio/_core/_run.py", line 1357, in spawn_impl
    hypercorn[497166]:     raise RuntimeError("Nursery is closed to new arrivals")
    hypercorn[497166]: RuntimeError: Nursery is closed to new arrivals
    @pgjones this was the last that we had. it came out of nowhere. it happens in the SSE endpoint handler which uses a global nursery assigned to g. and once it appeared first then for the next 24 hours it kept repeating so the SSE endpoint didn't work (although the rest of the app seemed to work)
    the other times it was different, but maybe related. some other small error in our code (could be anything, like a KeyError when accessing a dict item, for example) would cause the app to stop responding, but not crash, and no more error would show up in the logs ever. the only thing that would show up in the logs are these exact same nursery errors, always at this exact SSE handler.
    I was thinking of catching this RuntimeError and exiting the app when it happened so it could be restarted, but that sounded like a terrible hack, that's why I'm asking here what is the proper way to do it
    Phil Jones
    @pgjones
    g has a lifespan equal to the request, does it work if you assign the nursery to the app?
    fiatjaf
    @fiatjaf
    that's a good idea
    is that the recommended way? to assign the nursery to app?
    actually app.nursery already exists by default
    but app is not exposed anywhere because someone thought that was best practices so I can't access it from my handlers
    should I just ignore that and use a global app?
    do the nurseries get passed to blueprints too?
    fiatjaf
    @fiatjaf
    nevermind, we can just use current_app
    Phil Jones
    @pgjones
    Yea, I tend to put everything on the app and make use of current_app.
    luna
    @lun-4
    @pgjones just to not generate more noise in the repo, do your local changes also include a bump of swagger-ui to 3.47.1? We are currently on 3.37.2, the updates might be interesting to have (3.48 hasn't appeared on cdnjs yet)
    Phil Jones
    @pgjones
    No, happy to merge that
    luna
    @lun-4
    Got it!
    fiatjaf
    @fiatjaf
    hypercorn[721993]: Traceback (most recent call last):
    hypercorn[721993]:   File "/root/lnbits/venv/lib/python3.8/site-packages/quart_trio/app.py", line 151, in full_dispatch_request
    hypercorn[721993]:     result = await self.dispatch_request(request_context)
    hypercorn[721993]:   File "/root/lnbits/venv/lib/python3.8/site-packages/quart/app.py", line 1933, in dispatch_request
    hypercorn[721993]:     return await handler(**request_.view_args)
    hypercorn[721993]:   File "/root/lnbits/lnbits/decorators.py", line 28, in wrapped_view
    hypercorn[721993]:     return await view(**kwargs)
    hypercorn[721993]:   File "/root/lnbits/lnbits/core/views/api.py", line 313, in api_payments_sse
    hypercorn[721993]:     current_app.nursery.start_soon(payment_received)
    hypercorn[721993]:   File "/root/lnbits/venv/lib/python3.8/site-packages/trio/_core/_run.py", line 912, in start_soon
    hypercorn[721993]:     GLOBAL_RUN_CONTEXT.runner.spawn_impl(async_fn, args, self, name)
    hypercorn[721993]:   File "/root/lnbits/venv/lib/python3.8/site-packages/trio/_core/_run.py", line 1357, in spawn_impl
    hypercorn[721993]:     raise RuntimeError("Nursery is closed to new arrivals")
    hypercorn[721993]: RuntimeError: Nursery is closed to new arrivals
    @pgjones it didn't work
    nursery still closing even though it's on current_app now
    what am I doing wrong?
    Phil Jones
    @pgjones
    I'm not sure, could there be an uncaught exception in one of the tasks spawned in the nursery?
    Augusto Zanellato
    @augustozanellato
    I'm having some issues updating a project from 0.14.1 to 0.15.0, I'm using Flask-login and all the functions decorated by @login_required are now failing with the following error
    [2021-05-12 21:50:38,700] Error in ASGI Framework
    Traceback (most recent call last):
      File "/Users/augustozanellato/Library/Caches/pypoetry/virtualenvs/qcardealer-aBVvay5m-py3.9/lib/python3.9/site-packages/hypercorn/asyncio/context.py", line 39, in _handle
        await invoke_asgi(app, scope, receive, send)
      File "/Users/augustozanellato/Library/Caches/pypoetry/virtualenvs/qcardealer-aBVvay5m-py3.9/lib/python3.9/site-packages/hypercorn/utils.py", line 239, in invoke_asgi
        await app(scope, receive, send)
      File "/Users/augustozanellato/Library/Caches/pypoetry/virtualenvs/qcardealer-aBVvay5m-py3.9/lib/python3.9/site-packages/quart/app.py", line 1697, in __call__
        await self.asgi_app(scope, receive, send)
      File "/Users/augustozanellato/Library/Caches/pypoetry/virtualenvs/qcardealer-aBVvay5m-py3.9/lib/python3.9/site-packages/quart/app.py", line 1723, in asgi_app
        await asgi_handler(receive, send)
      File "/Users/augustozanellato/Library/Caches/pypoetry/virtualenvs/qcardealer-aBVvay5m-py3.9/lib/python3.9/site-packages/quart/asgi.py", line 51, in __call__
        _raise_exceptions(done)
      File "/Users/augustozanellato/Library/Caches/pypoetry/virtualenvs/qcardealer-aBVvay5m-py3.9/lib/python3.9/site-packages/quart/asgi.py", line 353, in _raise_exceptions
        raise task.exception()
      File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/tasks.py", line 256, in __step
        result = coro.send(None)
      File "/Users/augustozanellato/Library/Caches/pypoetry/virtualenvs/qcardealer-aBVvay5m-py3.9/lib/python3.9/site-packages/quart/asgi.py", line 102, in handle_request
        await asyncio.wait_for(self._send_response(send, response), timeout=timeout)
      File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/tasks.py", line 481, in wait_for
        return fut.result()
      File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/futures.py", line 201, in result
        raise self._exception
      File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/tasks.py", line 256, in __step
        result = coro.send(None)
      File "/Users/augustozanellato/Library/Caches/pypoetry/virtualenvs/qcardealer-aBVvay5m-py3.9/lib/python3.9/site-packages/quart/asgi.py", line 131, in _send_response
        async for data in response_body:
      File "/Users/augustozanellato/Library/Caches/pypoetry/virtualenvs/qcardealer-aBVvay5m-py3.9/lib/python3.9/site-packages/quart/wrappers/response.py", line 110, in _aiter
        for data in iterable:  # type: ignore
    TypeError: 'coroutine' object is not iterable
    Phil Jones
    @pgjones
    With Flask-Patch?
    Augusto Zanellato
    @augustozanellato
    I also have some custom decorators and I'm getting the same error with all the functions decorated by them

    With Flask-Patch?

    yep

    Phil Jones
    @pgjones
    Could you share a custom decorator?
    Augusto Zanellato
    @augustozanellato
    def require_admin(func):
        @wraps(func)
        def decorated_view(*args, **kwargs):
            if not current_user.is_authenticated or not current_user.is_admin:
                abort(werkzeug.exceptions.NotFound.code)
            else:
                return func(*args, **kwargs)
    
        return decorated_view