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

151
Views
JavaScript ES6 FastAPI Fetch da como resultado "Error de tipo"

Intento configurar una API simple en mi máquina local con FastAPI Backend y luego buscarla con un JS Script simple. Busqué en Google todo el día, pero todavía no puedo resolver el problema.

Podría apostar que me perdí algo.

El backend de FastAPI se ve así:

 from fastapi import FastAPI import uvicorn from fastapi.middleware.cors import CORSMiddleware app = FastAPI() origins = [ "http://localhost", "http://localhost:8000", "http://127.0.0.2", "http://127.0.0.2:8000" ] app.add_middleware( CORSMiddleware, allow_origins=origins, allow_credentials=False, allow_methods=["*"], allow_headers=["*"], ) @app.get("/") async def root(): return {"Message": "Root"} if __name__ == '__main__': uvicorn.run(app, host="127.0.0.2", port="8000")

Y Js Script se parece a:

 async function getRoot() { fetchAdresse = 'http://127.0.0.2:8000'; const response = await fetch(fetchAdresse, { method: 'GET', headers: { accept: 'html/text', }, }); console.log(response); } getRoot();

La respuesta es siempre la misma:

 Uncaught TypeError TypeError: Failed to fetch

Por otro lado, la respuesta del servidor es:

 INFO: 127.0.0.1:60927 - "GET / HTTP/1.1" 200 OK
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

"Error al obtener" puede significar muchas cosas diferentes.

Le sugiero que abra la pestaña de red en modo de inspección. Debe tener un aspecto como este: Pestaña de inspección de red de Devtools Cuando el programa recupera, debería haber una solicitud y deberías verla allí. A continuación, puede echar un vistazo al "estado" o hacer clic en la solicitud de un error más claro y luego buscarlo en Google.

about 4 years ago · Juan Pablo Isaza 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!