Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response streaming produces [ERROR] Invalid response type None (need HTTPResponse) #2911

Closed
1 task done
ekzhang opened this issue Jan 31, 2024 · 0 comments · Fixed by #2937
Closed
1 task done

Response streaming produces [ERROR] Invalid response type None (need HTTPResponse) #2911

ekzhang opened this issue Jan 31, 2024 · 0 comments · Fixed by #2937
Labels

Comments

@ekzhang
Copy link

ekzhang commented Jan 31, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

The "response streaming" feature of Sanic produces error messages when running from Uvicorn.

When accessing a page using the await request.respond() API, it produces error messages after each request.

[2024-01-31 19:37:14 +0000] [694830] [INFO] 
  ┌─────────────────────────────────────────────────────────────────────────────────┐
  │                                  Sanic v23.6.0                                  │
  │                                                                                 │
  ├───────────────────────┬─────────────────────────────────────────────────────────┤
  │                       │     mode: production, ASGI                              │
  │     ▄███ █████ ██     │   server: ASGI                                          │
  │    ██                 │   python: 3.11.6                                        │
  │     ▀███████ ███▄     │ platform: Linux-5.15.0-1048-aws-x86_64-with-glibc2.31   │
  │                 ██    │ packages: sanic-routing==23.12.0, sanic-testing==23.6.0 │
  │    ████ ████████▀     │                                                         │
  │                       │                                                         │
  │ Build Fast. Run Fast. │                                                         │
  └───────────────────────┴─────────────────────────────────────────────────────────┘

INFO:     Application startup complete.
INFO:     127.0.0.1:42186 - "GET / HTTP/1.1" 200 OK
[2024-01-31 19:38:19 +0000] [694830] [ERROR] Invalid response type None (need HTTPResponse)
Traceback (most recent call last):
  File "handle_request", line 144, in handle_request
    "_inspector",
            ^^^^^
sanic.exceptions.ServerError: Invalid response type None (need HTTPResponse)
[2024-01-31 19:38:19 +0000] [694830] [ERROR] The error response will not be sent to the client for the following exception:"Invalid response type None (need HTTPResponse)". A previous response has at least partially been sent.

Code snippet

from sanic import Sanic

app = Sanic("my-hello-world-app")


@app.route("/")
async def test(request):
    response = await request.respond(content_type="text/plain")
    await response.send("hello world")
    await response.eof()


if __name__ == "__main__":
    app.run()

Expected Behavior

Sanic should not produce error messages when using the response streaming API.

How do you run Sanic?

ASGI

Operating System

Linux

Sanic Version

23.6.0

Additional context

Possibly related to #2572, but it seems like a different issue. I can reproduce this without using WebSockets or SSE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant