Skip to content

RuntimeError: no validator found for <class 'starlette.responses.Response'> #8163

Closed Answered by jekirl
nrshapiro asked this question in Questions
Discussion options

You must be logged in to vote

Looks to be working with 0.31.0....Was that example in the docs for 0.27.2?

See below:

from starlette.responses import Response
from starlette.testclient import TestClient

app = FastAPI()


@app.get("/headers-and-object/")
def get_headers(response: Response):
    response.headers["X-Cat-Dog"] = "alone in the world"
    return {"message": "Hello World"}

def test_bug():
    client = TestClient(app)
    r = client.get("/headers-and-object/")
    assert r.headers["X-Cat-Dog"] == "alone in the world"
    assert r.json() == {"message": "Hello World"}```

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by Kludex
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants
Converted from issue

This discussion was converted from issue #358 on February 28, 2023 12:22.