emmett-framework / granian

A Rust HTTP server for Python applications
BSD 3-Clause "New" or "Revised" License
2.86k stars 83 forks source link

Example in README.md doesn't work #155

Closed myers closed 10 months ago

myers commented 10 months ago

I did roughly this:

mkdir test-granian
cd test-granian
poetry init -q
poetry add granian

create main.py

async def app(scope, receive, send):
    assert scope['type'] == 'http'

    await send({
        'type': 'http.response.start',
        'status': 200,
        'headers': [
            [b'content-type', b'text/plain'],
        ],
    })
    await send({
        'type': 'http.response.body',
        'body': b'Hello, world!',
    })
poetry run granian --interface asgi main:app

the first call to app is with a scope like {'type': 'lifespan', 'asgi': {'version': '3.0', 'spec_version': '2.3'}} which trips the assert. Removing the assert allows it to work.

gi0baro commented 10 months ago

@myers that's the ASGI lifespan protocol call. Doesn't granian just raise a warning message and keep serving the app?

myers commented 10 months ago

Ok, thank you I see now. You get an Assertion error, but it still works. May I suggest you handle that lifespan in some what that doesn't display an error? It is confusing if you are not aware of the differences between lifespan and http messages.