Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

461
Views
Siga recibiendo "307 Redirección temporal" antes de devolver el estado 200 alojado en la aplicación FastAPI + uvicorn + Docker: ¿cómo devolver el estado 200?

Editar:

Encontré el problema, pero no estoy seguro de por qué sucede esto. Cada vez que consulto: http://localhost:4001/hello/ con el " / " al final, obtengo una respuesta de estado 200 adecuada. No entiendo porque.

Publicación original:

Cada vez que envío una consulta a mi aplicación, sigo recibiendo una redirección 307. Cómo hacer que mi aplicación devuelva el estado normal 200 en lugar de redirigirla a través de 307

Esta es la salida de la solicitud:

 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

pytest devuelve:

 E assert 307 == 200 E + where 307 = <Response [307]>.status_code test_main.py:24: AssertionError

en mi directorio raíz: /__init__.py archivo:

 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'

Archivo /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"

en /Dockerfile :

 CMD ["uvicorn", "abm:abm", "--reload", "--proxy-headers", "--host", "0.0.0.0", "--port", "4001", "--forwarded-allow-ips", "*", "--log-level", "debug"]

Probé con y sin "--forwarded-allow-ips", "*" .

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Ocurre porque la ruta exacta definida por usted para su vista es yourdomainname/hello/ , por lo que cuando lo presiona sin / al final, primero intenta llegar a esa ruta, pero como no está disponible, vuelve a verificar después de agregar / y da un status code 307 y luego, cuando encuentra la ruta real, devuelve el código de estado que se define en la function/view vinculada con esa ruta, es decir status code 200 en su caso.

También puede leer más sobre el problema aquí: https://github.com/tiangolo/fastapi/issues/2060#issuecomment-834868906

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!