Я нашел проблему, но не знаю, почему это происходит. Всякий раз, когда я запрашиваю: http://localhost:4001/hello/ с помощью "
Код: Выделить всё
/Я не понимаю, почему.
Исходное сообщение:
Каждый раз, когда я отправляю запрос к своему приложению, я продолжаю получать перенаправление 307.
Как заставить мое приложение возвращать обычный статус 200 вместо перенаправления через 307
Это запрос вывод:
Код: Выделить всё
abm | INFO: 172.18.0.1:46476 - "POST /hello HTTP/1.1" 307 Temporary Redirect
abm | returns the apples data. nothing special here.
abm | INFO: 172.18.0.1:46480 - "POST /hello/ HTTP/1.1" 200 OK
Код: Выделить всё
E assert 307 == 200
E + where 307 = .status_code
test_main.py:24: AssertionError
Код: Выделить всё
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
# from .configs import cors
from .subapp import router_hello
from .potato import router_potato
from .apple import router_apple
abm = FastAPI(
title = "ABM"
)
# potato.add_middleware(cors)
abm.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
abm.include_router(router_hello.router)
abm.include_router(router_potato.router)
abm.include_router(router_apple.router)
@abm.post("/test", status_code = 200)
def test():
print('test')
return 'test'
Код: Выделить всё
/subapp/router_hello.pyКод: Выделить всё
router = APIRouter(
prefix='/hello',
tags=['hello'],
)
@router.post("/", status_code = 200)
def hello(req: helloBase, apple: appleHeader = Depends(set_apple_header), db: Session = Depends(get_db)) -> helloResponse:
db_apple = apple_create(apple, db, req.name)
if db_apple:
return set_hello_res(db_apple.potato.api, db_apple.name, 1)
else:
return "null"
Код: Выделить всё
CMD ["uvicorn", "abm:abm", "--reload", "--proxy-headers", "--host", "0.0.0.0", "--port", "4001", "--forwarded-allow-ips", "*", "--log-level", "debug"]
Подробнее здесь: https://stackoverflow.com/questions/703 ... ed-on-fast
Мобильная версия