_route_ method takes *_options which catches all keyword arguments and passes it further to *url_rule_class_ which -- in case of typo like 'method' instead of 'methods' -- leads to misleading exception:
[..]
File "/[..]/python2.7/site-packages/flask/app.py", line 943, in add_url_rule
rule = self.url_rule_class(rule, methods=methods, **options)
TypeError: __init__() got an unexpected keyword argument 'method'
why do you think that this exception is misleading? got an unexpected keyword argument 'method' sounds to me like exactly describing the problem if you supplied method instead of methods.
That's hard to fix due to how they work :(
@Turbo87 the problem is that it does not lead you to a place in your code where the mistake is. A new flask user will have to go through the code (like I did) to understand what the problem was.
@mitsuhiko I know it is hard to do but maybe someday someone who does not know that will just fix that? ;)
So how can I fix this issue? I'm new to Flask and Python and programming, and I'm baffled.
@davisclark Use 'methods' as the keyword argument, i.e. @app.route(methods=['GET', 'POST']).
Oh my god, that's incredible. A single route had been mistyped.
After 6 hours of searching line by line, I can't thank you enough.
+1, the error message is pretty misleading...
This post is now the 1st search result of goolge with keywords:" flask __init__() got an unexpected keyword argument 'method' "
Thanks to google, this message is perhaps no longer misleading...
I don't see a practical way to do this sort of typo checking in a general way, and don't think it's useful enough to justify the complexity. PyCharm, and possibly other IDEs, detect the correct kwargs. If you're not using the IDE, you're in the same situation here as you would be with any other code that uses this pattern. If anyone has a good argument and suggestion for why and how this should work, please open a new issue.
3 years later and I had the same misspelling! I have been using Flask for more than a year and this have never happened to me hehe. Thanks @Ceasar
5 years later my friend also had the same error . Thanks @Ceasar for saving us from hours of debugging.
Most helpful comment
@davisclark Use 'methods' as the keyword argument, i.e.
@app.route(methods=['GET', 'POST']).