Пытаюсь получить ответ от python что бы передать его в js.
Но взамен получаю ошибку:
На сервере ошибка:
CORS попытался настроить в .py
Тоже не дало результата.
Здесь я отправляю запрос в python ну и жду ответ
И дополнительно обрабатываю options
Надеюсь что здесь будут люди которые смогут помочь)
Но взамен получаю ошибку:
Код:
Access to fetch at 'url' from origin 'http://localhost' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
file.js:51
POST url net::ERR_FAILED
INFO: ip:port - "OPTIONS /123 HTTP/1.1" 404 Not FoundCORS попытался настроить в .py
Python:
router = APIRouter()
app = FastAPI()
app.include_router(router)
origins = [
"http://localhost",
"http://127.0.0.1:8080",
]
cors_middleware = CORSMiddleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.add_middleware(cors_middleware)
Здесь я отправляю запрос в python ну и жду ответ
JavaScript:
function 123() {
fetch(`url/123`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ id: Id })
})
.then(response => response.json())
.then(data => {
if (data.status === 'confirmed') {
clearInterval(123)
console.log("Получен ответ confirmed от сервера");
document.getElementById("123").textContent = "123";
alert("123");.
clearInterval(123);
}
})
Python:
@app.options("/123")
async def 123():
return JSONResponse(content={}, headers={
"Access-Control-Allow-Origin": "https://127.0.0.1:8000", "http://localhost"
"Access-Control-Allow-Methods": "POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type",
})
Надеюсь что здесь будут люди которые смогут помочь)