question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I prevent "307 Temporary Redirect" while accessing FastAPI via an Android Emulator on local machine

See original GitHub issue

The FastAPI REST API is working great when checked in the local browser and with the Advanced REST client Chrome plugin (only while using the XHR enabled).

But in no way are the same API accessible via the Android App running inside an emulator.

The info message in FastAPI console when accessed via Android App

127.0.0.1:57083 - "POST /v1/login HTTP/1.1" 307 Temporary Redirect

This is what is configured while loading the FastAPI

api = FastAPI(title=PROJECT_NAME)

if not ALLOWED_HOSTS:
    ALLOWED_HOSTS = ["*"]

api.add_middleware(
    CORSMiddleware,
    allow_origins=ALLOWED_HOSTS,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

Any help would be greatly appreciated. Screenshot 2019-11-24 at 11 50 46 AM

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:9
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

101reactions
dmontagucommented, Nov 25, 2019

Yeah, you can see it is trying to redirect you to the endpoint with a trailing slash:

< HTTP/1.1 307 Temporary Redirect
< date: Mon, 25 Nov 2019 03:22:56 GMT
< server: uvicorn
< location: http://localhost:8000/v1/login/

The problem is in code you didn’t share – wherever you’ve defined your endpoint, the path you are providing is ending with a "/". If you remove that trailing slash (or put a ? after it, if you want it to work both ways), this issue should go away.

It works in a browser just fine because the browser is just following the redirect automatically.

14reactions
dmontagucommented, Nov 24, 2019

Hard to say exactly what’s going on here without more detail (eg, what are the raw 307 http response contents? what is the redirect url? what do the server request logs contain?) but my guess is something is going on with a trailing slash. Possibly your android client is modifying the url to add a trailing slash? Or maybe performing some other url modification starlette is able to handle via redirect?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Keep getting "307 Temporary Redirect" before returning status ...
It happens because the exact path defined by you for your view is yourdomainname/hello/ , so when you hit it without / at...
Read more >
307 Temporary Redirect: What It Is and How to Fix It
A 307 Temporary Redirect response code indicates that the requested resource can be found at the new URI specified in the Location response ......
Read more >
307 Temporary Redirect: What It Is and How to Fix It- Android
A 307 Temporary Redirect message is an HTTP response status code indicating that the requested resource has been temporarily moved to another ...
Read more >
npmsearchfullcat_npm143.txt - GitHub
=flier 2012-07-10 0.2.0 android adb adb-cli a nodejs wrapper for adb to enable ... spam detection akismet-js Prevent comment spam using Akismet service…...
Read more >
GNU Guix Reference Manual
through the guix system command, even if you're using a different distro underneath ... your GNU/Linux machine (see [transparent-emulation-qemu], page 411).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found