본문 바로가기

FastApi

구름 IDE에서 FastAPI 실행

1. FastAPI

https://fastapi.tiangolo.com/ko/

 

FastAPI

FastAPI FastAPI 프레임워크, 고성능, 간편한 학습, 빠른 코드 작성, 준비된 프로덕션 문서: https://fastapi.tiangolo.com 소스 코드: https://github.com/tiangolo/fastapi FastAPI는 현대적이고, 빠르며(고성능), 파이썬

fastapi.tiangolo.com

2. 구름 IDE

https://ide.goorm.io/

 

구름IDE - 설치가 필요없는 통합개발환경 서비스

구름IDE는 언제 어디서나 사용 가능한 클라우드 통합개발환경(Integrated Development Environment IDE)을 제공합니다. 웹브라우저만 있으면 코딩, 디버그, 컴파일, 배포 등 개발에 관련된 모든 작업을 클라

ide.goorm.io

.3. 구름 IDE 컨테이너 생성

Jupyternotebook 으로 만들기

 

 4. main.py 만들기

#main.py
from typing import Union

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def read_root():
    return {"Hello": "World"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
    return {"item_id": item_id, "q": q}

 

5.실행

uvicorn main:app --reload --host=0.0.0.0 --port=80

--port=80

=> 프로젝트-속성-실행과 URL포트에서 등록된 URL과 포트의 포트 확인

 6. 접속

프로젝트-속성-실행과 URL포트에서 등록된 URL과 포트에서 URL 확인

 

7. Error처리

1) ImportError: cannot import name 'ParamSpec' from 'typing_extensions' (/usr/local/lib/python3.7/site-packages/typing_extensions.py)

=> typing_extensions 업데이트

pip install --upgrade typing-extensions

 

 2) Error loading ASGI app. Could not import module "main.py".

=> https://stackoverflow.com/questions/60819376/fastapi-throws-an-error-error-loading-asgi-app-could-not-import-module-api

 

FastAPI throws an error (Error loading ASGI app. Could not import module "api")

I tried to run FastAPI using uvicorn webserver but it throws an error. I run this command, uvicorn api:app --reload --host 0.0.0.0 but there is an error in the terminal. Uvicorn running on http://...

stackoverflow.com

src 디렉토리를 만든뒤 main.py 파일 옮기기

uvicorn src.main:app --reload --host=0.0.0.0 --port=80