Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Augusto Zanellato
    @augustozanellato

    Do you get the form data first?

    Maybe flask-wtf is getting the form data in order to check the csrf token

    Phil Jones
    @pgjones
    Yea it will
    Augusto Zanellato
    @augustozanellato
    Yep, that was the issue
    Phil Jones
    @pgjones
    The form parsing consumes the raw data
    You can get the raw data first, and then parse it
    Augusto Zanellato
    @augustozanellato
    That's not stated in the changelog, if it's intended it should be indicated I think
    Phil Jones
    @pgjones
    It is intended as it now matches how Flask works
    I've added a note to the Changelog
    Augusto Zanellato
    @augustozanellato
    Is it intended for the behavior to be dependent on the form type? If the enctype isn't set for the form everything works like it was in 0.14.x
    Phil Jones
    @pgjones
    It will need to be a form parse-able type
    Augusto Zanellato
    @augustozanellato
    Uhm, ok, will find a way to make flask-wtf work with that then
    Phil Jones
    @pgjones
    Why do you need the raw data separately to the form?
    Augusto Zanellato
    @augustozanellato
    Atm flask-wtf doesn't work, maybe it does some internal parsing of the form data, I'm looking into that now
    Phil Jones
    @pgjones
    oh, interesting
    Augusto Zanellato
    @augustozanellato
    This time I found the bug :P
    If I print request.form twice I get an empty dict the second time
        print(await request.form) #ImmutableMultiDict([('csrf_token', 'IjhkZjczMWZkNjc5MTM2YzBjZmZjYzI2MmVmZDBiYmYyZWI2YTIzZTIi.YKDkyQ.RCWggf-7baiOLQhl39EYWEIF6Uc'), ('email', 'aaaaaa@a'), ('password', 'aaaaaa')])
        print(await request.form) #ImmutableMultiDict([])
    Looking at the Quart source it looks like it's missing some check in Request._load_form_data so at every call it parses a new form from the request, without checking if a form has already been parsed first
    Phil Jones
    @pgjones
    Yep, just testing a fix. Thanks for figuring this out
    pgjones/quart@674983a hopefully fixes it
    (note the branch is now main)
    Augusto Zanellato
    @augustozanellato
    Now it's working fine, thanks :+1:
    Phil Jones
    @pgjones
    Great :)
    Augusto Zanellato
    @augustozanellato
    Found another thing :P
    Werkzeug's FileStorage.save accepts a PathLike or an already open file, Quart counterpart only accepts a PathLike
    Phil Jones
    @pgjones
    Yea, trickier one that - not sure how to handle open files with an async or sync interface
    Fame Castle
    @famecastle_gitlab

    Hello @pgjones ,
    first of all, thank you for your dedication to this whole project and the community - it's stunning!

    I'm having a concrete problem and I can't imagine the right approach to solve it.

    Let's say I'm having a Quart websocket endpoint like the simple echo example in here: https://pgjones.gitlab.io/quart/tutorials/websocket_tutorial.html#websockets

    Now, there's one source of incoming events which are awaited: the incoming messages (await websocket.receive())
    But in my case it's possible that I have an additional external source of events (say via await system.get_next_external_notification()). If either of them triggers (or in asyncio terms: "finishes"), I'd like to send a websocket message to my client.

    I guess I'll have to use something like asyncio.wait(..., return_value=asyncio.FIRST_COMPLETED) but I also want to be super sure that I don't miss any event if I only wait for the first completed one. I don't know how it would behave in the race condition of the two event sources almost triggering at the same time.

    Is there any standard pattern you could help me with?

    Thanks!

    András Mózes
    @mozesa

    Hello!
    I haven't followed this topic for a while. Now I have updated to Quart 15.1.0 and Quart-Trio 0.8.0.
    But whenever I close a websocket connection I get the following errors:

      File "C:\Users\mozesa\PycharmProjects\ACPS-ASM-PSA\.venv\lib\site-packages\trio\_core\_run.py", line 815, in __aexit__
        raise combined_error_from_nursery
    trio.MultiError: Cancelled(), Cancelled(), Cancelled()

    I didn't have this kind of error using Quart 14.1 with Quart-Trio 0.7.0.
    What I should watch for?

    Phil Jones
    @pgjones
    As when calling websocket.close()?
    Phil Jones
    @pgjones
    @famecastle_gitlab I think continually calling asyncio.wait is the best pattern. Maybe something like,
    websocket_task = asyncio.create_task(websocket.receive())
    other_task = asyncio.create_task(system.get_next_external_notification())
    while True:
        done, pending = await asyncio.wait(
            {websocket_task, other_task}, 
            return_when=asyncio.FIRST_COMPLETED,
        )
        # Do something with done
        if websocket_task in done:
            websocket_task =  asyncio.create_task(websocket.receive())
        if other_task in done:
            other_task = asyncio.create_task(system.get_next_external_notification())
    I.e. it continually creates new tasks whilst keeping any that didn't complete
    I've not tried this - I think it makes sense though
    András Mózes
    @mozesa
    @pgjones Hello!
    This snippet produces the following exception.
    The same code works fine using Quart v14.1.0 and QuartTrio v0.7.0.
    Montassar Ben Dhifallah
    @Momentum-TN

    hello everyone!
    I want to open tif files after being uploaded to the server using PILLOW. Here is the code:

    uploaded_files = (await request.files).getlist("files")
            timg = (await request.form).get('typeofimage')
            session['timg'] = timg
    
            if uploaded_files[0].filename!= "":
                session_files = []
                session_images = []
                for file in uploaded_files:
                    session_files.append(file.filename)
                    fpath = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
                    file.save(fpath)
    
                session['uploaded_files'] = session_files
                print(f"{len(uploaded_files)} files uploded successfully!")
                for f in session_files:
                    fpath = os.path.join(app.config['UPLOAD_FOLDER'], f)
                    im = Image.open(fpath)
                    print(type(im))

    Image.openraises PIL.UnidentifiedImageError: cannot identify image file

    How can I make quart wait until the files are saved ? because it seems that the openining happens before saving the files

    Phil Jones
    @pgjones

    @mozesa looks like this could be the issue,

      File "C:\Users\mozesa\PycharmProjects\ACPS-ASM-PSA\.venv\lib\site-packages\quart\app.py", line 1674, in finalize_websocket
        response = await self.postprocess_websocket(response, websocket_context)
      File "C:\Users\mozesa\PycharmProjects\ACPS-ASM-PSA\.venv\lib\site-packages\quart\app.py", line 1702, in postprocess_websocket
        session_ = (websocket_context or _request_ctx_stack.top).session
    AttributeError: 'NoneType' object has no attribute 'session'

    pgjones/quart#417

    @Momentum-TN (Don't forget about safe_join).
    Is it possible the error is that you aren't awaiting the save, await file.save(fpath)
    András Mózes
    @mozesa
    @pgjones Thanks for your help! I really appreciate it.
    dank-tagg
    @dank-tagg
    image.png
    Hello!
    I can't seem to solve this issue
    oops, meant
    No module named quart.exceptions
    Phil Jones
    @pgjones
    Ah, quart.exceptions is now werkzeug.exceptions i.e. the Werkzeug exceptions are used instead
    Cobalt
    @Chaostheorie
    Hey. I've tried to migrate my exception handling to werkzeug. But the response produced by werkzeugs exceptions seem to be incompatible with quarts ASGI response sender:
    Cobalt
    @Chaostheorie
    I'm kinda confused on how to hanlde those new exceptions: MRE
    Is this expected behaviour and if not how can I mitigate this problem. (I have also tried just returning the exception, but that doesn't work either)
    Phil Jones
    @pgjones
    Could you confirm what Quart version you are using? (I think I've fixed this bug in 0.15.1)
    Cobalt
    @Chaostheorie
    @pgjones just noticed I was using 0.14.x. Resolved itself (still had a bug, but that's solved now) with the new version and using Quart instead of quart. I thought I already had the latest with poetry update, but I didn't notice the naming change
    Thank you for you help anyways :)
    Phil Jones
    @pgjones
    I don't understand what you mean by Quart instead of quart?
    Penguin Master
    @penguinmaster_gitlab
    When I use request.forms to view the image that was uploaded through an HTML5 input (type="file"), it shows a file name. How can I get the bytes of an image uploaded through an HTML5 input?
    @pgjones
    Phil Jones
    @pgjones
    What does request.files show?