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.

Undue 405 error with POST request

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Troniccommented, Jan 20, 2022

@ahopkins Could we change the default to True in 22.3? This confusion is becoming a FAQ.

Read more comments on GitHub >

github_iconTop 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 >

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