Errata

FastAPI

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
O'Reilly learning platform Page Chapter 3. FastAPI Tour
HTTP Responses --> Status Code

I'm enjoying this book very much so far (chapter 3). I am very, very confident that it will stay that way :)

The description in the text is correct:
"In the path decorator, specify the HTTP status code that should be returned if all goes well (exceptions will generate their own codes and override it)."

But the code example puts the status code in the parameter list of the path function. It won't generate an error but won't work either.

The code example should look like this:
@app.get("/happy", status_code=202)
def happy():
return ":)"

Ralf Schmitt  Dec 31, 2023 
O'Reilly learning platform Page Example 3-24
Example 3-24

Example, when run with HTTPie returns a HTTP/1.1 405 - Method Not Allowed

Ken LaCrosse  May 17, 2024 
PDF Page Page 79,
Example 6-1.

code:
from fastapi import FastAPI, Depends, Params

problem:
There is no Params module in FastAPI

Anonymous  Jun 05, 2024 
ePub Page Example 3-26
@app.post("/agent")

POST method used in the example causes the following answer:
HTTP/1.1 405 Method Not Allowed
allow: POST
content-length: 31
content-type: application/json
date: Thu, 04 Jul 2024 17:41:08 GMT
server: uvicorn

{
"detail": "Method Not Allowed"
}

But when I change @app.post to @app.get the error disappears.

Tomasz Janicki  Jul 04, 2024 
O'Reilly learning platform Page Chapter 3. FastAPI Tour, Section : HTP Responses
4th Para (Status Code)

In the source code the status code should be defined in path parameter

@app.get("/happy", status_code=200)

but instead it is inside method definition
def happy(status_code=200):

Subhadeep  Jul 16, 2024 
ePub Page Examples 9-4, 12-14
Varies

in eample 9-3, service/test_creature.py contains "from service import creature as code" while in example 12-14 there is no such import. In the files downloaded from Git, fastapi main/src/test/unit/service/test_explorer.py, the statement is "from web import creature", while in .../unit/web/test_explorer.py contains "from web import explorer
". This is confusing. Why import from web if you are testing service?

John Terry  May 23, 2025 
Other Digital Version Example 8-13, Page 106
Inside the for loop in get_one() function definition

The get_one function performs a case sensitive string comparison (_creature.name == name). But, the unit test in Example 9-3 pass a lowercase string "yeti" while the data in _creatures is capitalized as "Yeti".

Correction: Use .lower() on both sides of the comparison to ensure case insensitive matching.

Code Change:
if _creature.name.lower() == name.lower():

Raghav Gupta  Mar 06, 2026 
Mobi Page Example 9-3, Page 119
Inside sample creature object in example 9-3

The sample Creature object is defined with name="yeti", but the fake data layer contains "Yeti". Even with case insensitive searching, the final equality assertion (assert resp == sample) will fail because Pydantic / Python object equality is case sensitive for string fields.

Correction: Update the sample object's name to match the casing in the data layer.

Code Change:
sample = Creature(name="Yeti", ...)

Raghav Gupta  Mar 06, 2026 
Other Digital Version Example 9-3, Page 119
Inside test_get_missing function definition

In the test_get_missing function, the assertion checks a variable named data (assert data is None). However the result of the function call was assigned to the variable resp. This results in a NameError.

Correction: Change the assertion to reference the correct variable.

Code Change:
def test_get_missing():
resp = code.get_one("boxturtle")
assert resp is None

Raghav Gupta  Mar 06, 2026 
Printed Page 38
Example 3-26. Return the User-Agent header (hello.py)

`@app.post("/agent")` should be `@app.get("/agent")`.

Zhi Li  May 17, 2024 
PDF Page 52
last line

This command doesn't work:
$ http -b localhost:8000/hi?who=Mom

You need add commas:
$ http -b "localhost:8000/hi?who=Mom"

Alex  Mar 02, 2025 
Printed Page 55, 56
3.24, 3.26 samples

It should be GET instead of POST request for correct work

from fastapi import FastAPI, Header
app = FastAPI()
@app.get("/agent") #ERROR in book is written @app.get("/agent")
def get_agent(user_agent:str = Header()):
return user_agent

Alex  Mar 03, 2025 
Printed Page 57-58
bottom

One more error in written code here:
@app.get("/happy")
def happy(status_code=200):
return ":)"

It should be inside the decorator like in this example:
@app.get("/happy", status_code=288)
async def happy():
return ":)"

In this case of check it with HTTPie request: $ http localhost:8000/happy
You will get:
HTTP/1.1 288
content-length: 4
content-type: application/json
date: Tue, 04 Mar 2025 01:42:16 GMT
server: uvicorn

":)"

alex  Mar 04, 2025 
PDF Page 71
Example 5-12. Start Uvicorn

In example 5-12. "Start Uvicorn" you need to type "uvicorn web:app" instead of "uvicorn creature:app" in order to start the server (if you follow the same naming convention of the example).

Matthias Roecklinger  Sep 20, 2024 
PDF Page 85
Example 7-5

The example 7-5 should be the copy of the example 3-21 but it is not.
This example is for Fastapi Body and need Body(embed=True) but instead this example is the copy of example 7-3 which is for Fastapi query parameter.

Hossein Tahami  Jul 08, 2024 
PDF Page 98 - 100
Example 8-1 & 8-4

In example 8-1 the (import uvicorn) is inside the
if __name__ == "__main__" but in example 8-4
it is outside the condition.

Hossein Tahami  Jul 08, 2024 
PDF Page 107
Example 8-14

The delete path function in web/explorer.py should return
service.delete(name) but instead it's only returning None exactly like the delete function in fake/explorer.py
Also delete path function in web/creature.py in the next example which is 8-15 is returning service.delete(name) but the 8-14 is not.

Hossein Tahami  Jul 08, 2024 
PDF Page 117
Example 9-1 & 9-2

get_one function in service/creature.py returns data.get(id) but the same function in service/explorer.py returns data.get(name)
argument of this function is <<name>> with string type.

Hossein Tahami  Jul 09, 2024 
Printed Page 170,176,
example 12-5,

Example 12-5: the function names mismatch with the explanation of the arguments such as the function name is test_summer_b() and the argument is described as test_caller_b(). And also, the names are not consistent in the example.

The example 12-14 /unit/service/test_creature.py has import statement as: "from data import creature as data". But we are testing here the service and it should be "from service import creature as data".

Please contact me if you would like to have full list of my update to include in the github source code version.

Thank you,

Best regards,
Battogtokh

Battogtokh Baasanjav  Feb 07, 2025