-
|
Used the very code on the docs for simple posting and it only allows me to use get |
Beta Was this translation helpful? Give feedback.
Replies: 27 comments 12 replies
-
|
actually the log shows im using GET although in code im using POST |
Beta Was this translation helpful? Give feedback.
-
|
What was the resolution for this issue? I am getting same behavior. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks @Finix21 for reporting back and closing the issue 👍 @nikhilno1 you might want to follow the tutorial exactly as is. With the integrated docs UI to send the POST and confirm that it works. Then you can check in your own code, gradually what is different. |
Beta Was this translation helpful? Give feedback.
-
|
@tiangolo Hi. I am running into the same issue as mentioned above. Going through the tutorial, and not one of the snippets here work. The issue is, as @Finix21 mentions, that the code correctly states that the method should run on a POST request, the server executes it as a GET request. As an example, this code: from typing import Optional
from fastapi import FastAPI
from pydantic import BaseModel
class Item(BaseModel):
name: str
description: Optional[str] = None
price: float
tax: Optional[float] = None
app = FastAPI()
@app.post("/items/")
async def create_item(item: Item):
return itemwill result in This is true for all snippets on that page. I have tried without Running on Windows 10 64x, Python 3.8.2:
|
Beta Was this translation helpful? Give feedback.
-
|
@BramVanroy can you try sending a curl request? The code snippet you have works well for me Out: {"name":"string","description":"string","price":0.0,"tax":0.0} |
Beta Was this translation helpful? Give feedback.
-
|
@ycd The cURL request works, but the browser doesn't seem to be playing nicely: I am just surfing to |
Beta Was this translation helpful? Give feedback.
-
|
So the issue was that the example of course will not run because we never do a POST operation. Perhaps that can be improved in the documentation, as inexperienced users may think that all code snippets are executable - but the example above will not work (because we are just GETting). |
Beta Was this translation helpful? Give feedback.
-
|
The error is raised by HTTP server it never reaches to FastAPI you can check that by using |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
I am having the same issue. On localhost everything works as expected from postman. Then after deploying it on google cloud run I keep having |
Beta Was this translation helpful? Give feedback.
-
|
@dnhyde I'm having the exact same problem as you. I deployed my FastAPI source code to Cloud Run and now when I try to make a POST, it returns |
Beta Was this translation helpful? Give feedback.
-
|
@dnhyde I think I solved my issue. I was trying to make a POST request to my Google Cloud Run service without |
Beta Was this translation helpful? Give feedback.
-
|
@caioalmeida97 : thank you SO MUCH for this "HTTPS prefix" tip, it really helped me to solve the same problem I was facing 👍👍 |
Beta Was this translation helpful? Give feedback.
-
|
I tried adding https prefix but I ended up getting this site can't be reached |
Beta Was this translation helpful? Give feedback.
-
|
I am still getting error 405. Could anyone tell how to solve it? |
Beta Was this translation helpful? Give feedback.
-
|
For me the problem was that because of a config mismatch when converting from Node, the route was at
instead of
and changing it fixed the problem. |
Beta Was this translation helpful? Give feedback.
-
|
For me it was also the lack of a trailing /, using requests.post to a post route. It would be great if this could be fixed to raise another error because this was a tricky debug. |
Beta Was this translation helpful? Give feedback.
-
|
i had the same issue because i was mounting |
Beta Was this translation helpful? Give feedback.
-
|
Hey all! Thanks for the conversation here. If anyone is still having problems, it's better to create a new issue, following the template and writing a self contained example. If you check closely, even though the problem was visible as a 405 error, the cause was very different in several cases, so, it was actually not the same problem. That's why it's better to create a new issue with all the description and a self contained example. |
Beta Was this translation helpful? Give feedback.
-
|
Hi, I'm trying to use the fast api with Stable Difussion UI -- the Automatic 1111 i tried to follow this : https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/API
|
Beta Was this translation helpful? Give feedback.
-
|
因为我挂载StaticFiles在根路径 ( /) 上,这意味着我所有的 POST 都被解释为静态文件请求 |
Beta Was this translation helpful? Give feedback.
-
|
I found this issue as well. Please find here a great explanation for those cases in which serving static html files might be colliding with depth routes: https://stackoverflow.com/a/73113792 |
Beta Was this translation helpful? Give feedback.
-
|
Hi Lucas,
I did. A novice mistake due to the lack of examples and guideline out
there. With API usually you will find a lot of fetch examples online but
not post examples. So my post api method had the wrong argument type.
Hope this helps.
Rainer
…On Fri, Nov 17, 2023 at 2:59 PM Lucas Colas ***@***.***> wrote:
Did you find a solution ?
—
Reply to this email directly, view it on GitHub
<#7859 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABR72RLYUVZ5GTRNH2SO7ALYE663VAVCNFSM6AAAAAAWSR2X22VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM3TMMBSHAZDE>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
|
I spent days troubleshooting my frontend post function, I wasn't sure my
javascript function was correct as a JS newbie, and also troubleshooting my
nginx (web server and load balancer) in case it was changing the type of
request or redirecting incorrectly, so after trying everything that made
sense to me at the time, I decided to start looking elsewhere so I
arrive to the API from there I tried different version of the function,
play with different types of possible annotations, etc... until I started
playing with the arguments of the post function.
This is the working method:
from fastapi import Body
@router.post(path="/api/endpoint/add_email")
def add_email(email: str = Body()) -> bool:
pass
The bad example:
@router.post(path="/api/endpoint/add_email")
def add_email(email: str = ***@***.***") -> bool:
pass
In conclusion, my FastApi wasn't assigning the request to my add_email
endpoint due to the argument type or the endpoint itself didn't understand
the argument I was passing to it.
Again, hope this helps.
Rainer
…On Fri, Nov 17, 2023 at 3:15 PM Lucas Colas ***@***.***> wrote:
But how did you figure it out ? I'm also stuck with the same error.
—
Reply to this email directly, view it on GitHub
<#7859 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABR72RLY3RHWBFS66TYM463YE7AWVAVCNFSM6AAAAAAWSR2X22VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM3TMMBSHEYTO>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
|
For people who are experiencing this - this is what I found in my case. Everything worked locally, but we had weird behavior when deploying to Lightsail. Things like HTTP to HTTPS issues, or routes getting mixed up. The root cause was deploying FastAPI behind a proxy/load balancer (Lightsail's) that gets confused. In my case, the --proxy-headers parameter for uvicorn did the trick. |
Beta Was this translation helpful? Give feedback.
-
|
I encountered this problem too. It worked well locally, but when I deployed it to the Azure App Service, I got this error: 405 Method Not Allowed. After a day and a half, I finally found the root cause. It was just missing an 's'; I should have used HTTPS instead of HTTP. |
Beta Was this translation helpful? Give feedback.
-
|
Change http to https for POST request and it shall work. |
Beta Was this translation helpful? Give feedback.

For me the problem was that because of a config mismatch when converting from Node, the route was at
instead of
and changing it fixed the problem.