Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- 안드로이드
- 스피너
- ChatGPT
- android ktor
- ktor api call
- Python
- doc2vec
- build with ai
- kotlin collection
- getChangePayload
- ansi2html
- exoplayer cache
- ktor client
- ExoPlayer
- llm
- video caching
- kotlin list
- 시행착오
- android
- AWS EC2
- 독서
- DiffUtil.ItemCallback
- android exoplayer
- FastAPI
- list map
- 유튜브
- map
- ListAdapter DiffUtil
- ListAdapter
- android custom view
Archives
- Today
- Total
버튼 수집상
[FastAPI] Pydantic field 타입 에러 (fastapi.exceptions.FastAPIError: Invalid args for response field!) 본문
TIL - Python
[FastAPI] Pydantic field 타입 에러 (fastapi.exceptions.FastAPIError: Invalid args for response field!)
cocokaribou 2023. 7. 19. 12:46FastAPI 공식 문서를 참고해서 token api를 구현했다.
@app.post("/token")
async def login(form_data: Annotated[OAuth2PasswordRequestForm, Depends()]):
user_dict = fake_users_db.get(form_data.username)
if not user_dict:
raise HTTPException(status_code=400, detail="Incorrect username or password")
user = UserInDB(**user_dict)
hashed_password = fake_hash_password(form_data.password)
if not hashed_password == user.hashed_password:
raise HTTPException(status_code=400, detail="Incorrect username or password")
return {"access_token": user.username, "token_type": "bearer"}
그런데 로컬에서는 빌드가 잘 되는데, 원격 서버에서는 Pydantic 타입 에러가 떴다.
fastapi.exceptions.FastAPIError: Invalid args for response field! Hint: check that typing.Annotated[fastapi.security.oauth2.OAuth2PasswordRequestForm, Depends(NoneType)] is a valid Pydantic field type. If you are using a return type annotation that is not a valid Pydantic field (e.g. Union[Response, dict, None]) you can disable generating the response model from the type annotation with the path operation decorator parameter response_model=None. Read more: https://fastapi.tiangolo.com/tutorial/response-model/
Annotated 안에 인자를 어떻게 바꿔줘도 같은 에러가 떴다.
그러다가 두 서버에 설치된 fastapi 버전을 체크했는데 차이가 있었다.
pip freeze | grep fastapi
fastapi==0.97.0
fastapi==0.93.0
FastAPI requirements.txt에 버전정보를 명시해주자 잘 해결됐다.
fastapi==0.97.0
pymssql
fastapi_pagination
728x90
'TIL - Python' 카테고리의 다른 글
[FastAPI] 인트라넷 앱을 위한 크롤링 API 만들기 - 1. screen 세션 (0) | 2024.02.13 |
---|---|
[FastAPI] 인트라넷 앱을 위한 크롤링 API 만들기 - 0. 소개 (0) | 2024.02.13 |
[Python] 쿼리 읽기가 어려워서 ORM을 써봤다. (0) | 2023.11.19 |
[Python] pymssql INSERT 할 때 중복값 체크해서 업데이트하기 (0) | 2023.05.23 |