Undue 405 error with POST request
See original GitHub issueDescribe the bug
Sanic gives a HTTP 405 on POST request while it should give a HTTP 200. Problem does not happen with previous Sanic versions.
Code snippet
Example app:
from sanic import Sanic
from sanic.response import text
app = Sanic("test")
@app.route("/test/", methods=["POST"])
def do_post(request):
return text("from post")
@app.route("/test/<foo>", methods=["GET"])
def do_get(request, foo):
return text(foo)
app.run()
Client test:
user/Downloads : python3
Python 3.9.4 (v3.9.4:1f2e3088f3, Apr 4 2021, 12:19:19)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from requests import get, post
>>> (post("http://localhost:8000/test/"), get("http://localhost:8000/test/ok"))
Result with Sanic 21.12.1:
(<Response [405]>, <Response [200]>)
Result with Sanic 20.12.3:
(<Response [200]>, <Response [200]>)
Expected behavior
Sanic should give an HTTP 200 to the POST request.
Environment (please complete the following information):
- OS: MacOS
- Version 12.1
Additional context
Complete server traces:
(oldsanic 20.12.3) user/Downloads : python app.py
[2022-01-20 17:27:26 +0100] [76738] [INFO] Goin' Fast @ http://127.0.0.1:8000
[2022-01-20 17:27:26 +0100] [76738] [INFO] Starting worker [76738]
[2022-01-20 17:27:31 +0100] - (sanic.access)[INFO][127.0.0.1:64750]: GET http://localhost:8000/test/ok 200 2
[2022-01-20 17:27:32 +0100] - (sanic.access)[INFO][127.0.0.1:64752]: POST http://localhost:8000/test/ 200 9
(newsanic 21.12.1) user/Downloads : python app.py
[2022-01-20 17:26:17 +0100] [76690] [INFO]
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Sanic v21.12.1 โ
โ Goin' Fast @ http://127.0.0.1:8000 โ
โโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ mode: production, single worker โ
โ โโโโ โโโโโ โโ โ server: sanic โ
โ โโ โ python: 3.9.4 โ
โ โโโโโโโโ โโโโ โ platform: macOS-12.1-arm64-arm-64bit โ
โ โโ โ packages: sanic-routing==0.7.2 โ
โ โโโโ โโโโโโโโโ โ โ
โ โ โ
โ Build Fast. Run Fast. โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
[2022-01-20 17:26:17 +0100] [76690] [WARNING] Sanic is running in PRODUCTION mode. Consider using '--debug' or '--dev' while actively developing your application.
[2022-01-20 17:26:17 +0100] [76690] [INFO] Starting worker [76690]
[2022-01-20 17:26:23 +0100] - (sanic.access)[INFO][127.0.0.1:64723]: GET http://localhost:8000/test/ok 200 2
[2022-01-20 17:26:25 +0100] - (sanic.access)[INFO][127.0.0.1:64725]: POST http://localhost:8000/test/ 405 757
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
How to Fix the HTTP 405 Method Not Allowed Error - Kinstaยฎ
It's an HTTP response status code that indicates that the request method is known by the server but is not supported by the...
Read more >How to Fix HTTP Error 405 Method Not Allowed - Hostinger
When a website shows the 405 Method Not Allowed notification, it indicates a Hypertext Transfer Protocol (HTTP) error.
Read more >405 Method Not Allowed: What It Is and How to Fix It
The 405 Method Not Allowed is an HTTP response status code indicating that the server received and recognized the specified request HTTP ......
Read more >How To Effectively Fix an HTTP 405 Error With 7 Methods
How can you fix an HTTP 405 error? ยท 1. Double-check the website's URL ยท 2. Undo recent upgrades ยท 3. Uninstall new...
Read more >HTTP Status 405 - Method Not Allowed Error for Rest API
Are you using HTTP GET to access the URL? ยท 405 usually means you either tried a GET on something that only allows...
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
@ahopkins Could we change the default to
True
in 22.3? This confusion is becoming a FAQ.https://sanic.dev/en/guide/basics/routing.html#strict-slashes
https://community.sanicframework.org/t/route-paths-how-do-they-work/825?u=ahopkins