How can I prevent "307 Temporary Redirect" while accessing FastAPI via an Android Emulator on local machine
See original GitHub issueThe 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.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:9
- Comments:7 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, you can see it is trying to redirect you to the endpoint with a trailing slash:
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.
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?