반응형
[FastAPI] Error 모음집
·
Programming/Python
Database 관련 1. sqlalchemy.exc.InvalidRequestError: Class does not have a __table__ or __tablename__ specified and does not inherit from an existing table-mapped class. 선언한 클래스에 테이블 이름을 지정하지 않아서 나타는 문제이다, 해당 클래스에 테이블명을 선언하면 된다. (이전) class Blog(Base): ... (변경) class Blog(Base): __tablename__ = 'blog' ... 2. sqlalchemy.exc.CompileError: (in table 'blog', column 'body'): VARCHAR requires a length on..
[Python] Pycharm 에러 해결법 정리
·
Programming/Python
1. 인코딩 에러 (debug를 진행 할 때 나타나는 에러였다.) Fatal Python error: init_stdio_encoding: failed to get the Python codec name of the stdio encoding Python runtime state: core initialized LookupError: unknown encoding: x-windows-949 Current thread 0x00003934 (most recent call first): 윈도우 기준 : Ctrl + alt +s 를 눌러 설정창에 진입한다 (메뉴 창으로는 : File > Settings) 셋팅 창을 띄우고나면, 검색 영역에 "encoding"을 검색하여 Encoding을 바꿀수 있는 메뉴를 확인..
[에러] 파이썬 가상환경 보안 에러
·
Programming/Python
이 시스템에서 스크립트를 실행할 수 없으므로 D:\project\python\api\....\venv\Scripts\Activate.ps1 파일을 로드할 수 없습니다아... 자꾸 Pycharm에 들어갈때마다 에러 메시지가 뜬다. (참다 참다 귀찮아져서 해당부분을 해결해보고자 한다.) 1.  powershell을 관리자 모드로 열어준다. 2.관리자 모드로 열린 Powershell에 Set-ExecutionPolicy Unrestricted를 입력해주고, "Y"선택값을 통해 변경을 한다. 3.Ta-da.... 정상 작동됨을 알 수 있다..위의 명령어 하나만 입력하면 되는걸 귀찮아서 안한 내 자신에게 박수를 표하며.. 혹시나 컴퓨터를 바꾸게 되는 경우를 위해 기록해둔다..
[FastAPI] 응답 모델
·
Programming/Python
FastAPI 목차 FastAPI 소개 FastAPI 설치 경로 매개변수 쿼리 매개변수 요청 본문 응답 모델 모든 경로 작업에서 response_model 매개 변수를 사용하여 반응에 사용되는 모델을 선언할 수 있습니다. from typing import Optional from fastapi import FastAPI from pydantic import BaseModel app = FastAPI() class User(BaseModel): name: str password: str @app.post("/users", response_model=User) #응답 모델 def create_user(user: User): #요청 모델 return user 해당 코드를 작성하고 "http://localhos..
[FastAPI] 요청 본문
·
Programming/Python
FastAPI 목차 FastAPI 소개 FastAPI 설치 경로 매개변수 쿼리 매개변수 요청 본문 POST, PUT, DELETE, PATCH와 같은 메서드를 사용하여 데이터를 전송하는 경우 요새는 JSON을 이용합니다. from typing import Optional from fastapi import FastAPI from pydantic import BaseModel, HttpUrl app = FastAPI() class User(BaseModel): name: str password: str avatar_url: Optional[HttpUrl] = None @app.post("/users") def create_user(user: User): return user 해당 코드에서 User클래스는 ..
[FastAPI] 쿼리 매개변수
·
Programming/Python
FastAPI 목차 FastAPI 소개 FastAPI 설치 경로 매개변수 쿼리 매개변수 쿼리란 URL에서 ? 후에 나오고 &으로 구분되는 키와 값의 집합입니다. 예를 들어서 https://ssue-dev.tistory.com?category_id=1&post_id=1와 같은 URL이 있을 때 쿼리 매개변수는 category_id : 값 1을 가지며, post_id: 값 1을 가집니다. from fastapi import FastAPI app = FastAPI() @app.get("/users") def get_users(limit: int): return {"limit": limit} 해당 코드를 작성한 뒤 http://127.0.0.1:8000/users?limit=100를 호출하게 된다라면 {"lim..
반응형
개발자 쓔쓔