INFO: 127.0.0.1:59446 - "GET /redoc HTTP/1.1" 200 OK
INFO: 127.0.0.1:59446 - "GET /openapi.json HTTP/1.1" 500 Internal Server Error
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/home/ubuntu/git/rowmate/api/venv/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 390, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "/home/ubuntu/git/rowmate/api/venv/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
return await self.app(scope, receive, send)
File "/home/ubuntu/git/rowmate/api/venv/lib/python3.8/site-packages/fastapi/applications.py", line 179, in __call__
await super().__call__(scope, receive, send)
File "/home/ubuntu/git/rowmate/api/venv/lib/python3.8/site-packages/starlette/applications.py", line 111, in __call__
await self.middleware_stack(scope, receive, send)
File "/home/ubuntu/git/rowmate/api/venv/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
raise exc from None
File "/home/ubuntu/git/rowmate/api/venv/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
await self.app(scope, receive, _send)
File "/home/ubuntu/git/rowmate/api/venv/lib/python3.8/site-packages/starlette/middleware/cors.py", line 78, in __call__
await self.app(scope, receive, send)
File "/home/ubuntu/git/rowmate/api/venv/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__
raise exc from None
File "/home/ubuntu/git/rowmate/api/venv/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in __call__
await self.app(scope, receive, sender)
File "/home/ubuntu/git/rowmate/api/venv/lib/python3.8/site-packages/starlette/routing.py", line 566, in __call__
await route.handle(scope, receive, send)
File "/home/ubuntu/git/rowmate/api/venv/lib/python3.8/site-packages/starlette/routing.py", line 227, in handle
await self.app(scope, receive, send)
File "/home/ubuntu/git/rowmate/api/venv/lib/python3.8/site-packages/starlette/routing.py", line 41, in app
response = await func(request)
File "/home/ubuntu/git/rowmate/api/venv/lib/python3.8/site-packages/fastapi/applications.py", line 128, in openapi
return JSONResponse(self.openapi())
File "/home/ubuntu/git/rowmate/api/venv/lib/python3.8/site-packages/fastapi/applications.py", line 106, in openapi
self.openapi_schema = get_openapi(
File "/home/ubuntu/git/rowmate/api/venv/lib/python3.8/site-packages/fastapi/openapi/utils.py", line 343, in get_openapi
definitions = get_model_definitions(
File "/home/ubuntu/git/rowmate/api/venv/lib/python3.8/site-packages/fastapi/utils.py", line 24, in get_model_definitions
m_schema, m_definitions, m_nested_models = model_process_schema(
File "pydantic/schema.py", line 467, in pydantic.schema.model_process_schema
File "pydantic/schema.py", line 503, in pydantic.schema.model_type_schema
File "pydantic/schema.py", line 184, in pydantic.schema.field_schema
File "pydantic/schema.py", line 767, in pydantic.schema.encode_default
File "pydantic/json.py", line 60, in pydantic.json.pydantic_encoder
File "pydantic/json.py", line 21, in pydantic.json.lambda
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x88 in position 0: invalid start byte
Basically I run http://localhost:8000/redoc and I get the above error in the terminal. I googled and searched in Github issues on FastAPI project and looked in Redoc and Pydantic issues but could not find any similar issue. I have no idea how to fix this and even nor if this really comes from FastAPI. But if one could have a look would be great.
Your issue is here: https://github.com/maurosbicego/rowmate/blob/master/api/models/boat.py#L14
```python
class Boat(BaseModel):
id: Binary = Binary(bytes(bytearray(uuid4().bytes)), UUID_SUBTYPE)
````
remove the default, and that should fix it (because pydantic tries to encode the binary uuid as a string for the openapi.json)
Thank you soooooo much, removing the default did help to run /redoc or /docs without issues.
I changed class Boat and others from
class Boat(BaseModel):
id: Binary = Binary(bytes(bytearray(uuid4().bytes)), UUID_SUBTYPE)
class Boat(BaseModel):
id: Binary
I'm going to close this issue.