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

421
Views
how to route from one api to other fastapi

I am trying to redirect request from protected_api() to login() function in fastapi. but it fails with messages

Failed to fetch. Possible Reasons: CORS Network Failure URL scheme must be "http" or "https" for CORS request.

what could be the issue and how can be redirect from one api to other

@app.get("/protected_api")
async def protected_api():    
    resp = RedirectResponse("https://localhost:5000/token")
    return resp
    
@app.post("/token", response_model=Token)
async def login(form_data: OAuth2PasswordRequestForm = Depends()):  # login function to get access token
    print('In login fun value of form_data dict.....%s' % form_data.__dict__)
    user = authenticate_user(fake_users_db, form_data.username, form_data.password)
    if not user:
        raise HTTPException(
            status_code=status.HTTP_401_UNAUTHORIZED,
            detail="Incorrect username or password",
            headers={"WWW-Authenticate": "Bearer"},
        )
    access_token_expires = timedelta(seconds=ACCESS_TOKEN_EXPIRE_SECONDS)
    access_token = create_access_token(
        data={"sub": user.username}, expires_delta=access_token_expires
    )
    print('Value of access_token in login fun ......%s\n' % access_token)
    return {"access_token": access_token, "token_type": "bearer"}   
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You're having clients ping A (/protected_api) but sending a response from B (/token). They are not the same endpoint, so this involves CORS. Try using CORSMiddleware with FastAPI to resolve this issue.

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!