-
-
Notifications
You must be signed in to change notification settings - Fork 16.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
app.run(port='5000', debug=True) error #2220
Comments
Ports are numbers, not strings. However, I agree that it'd be nicer to fail in both cases. |
Can I submit a PR for this? I may have time this weekend. But, of course, if you want to do it you can go with it :) Maybe a good solution is to check types and raise TypeError? |
@aaossa Yes and yes. Also please add a test :) |
Reading the source code, I thought, is this Werkzeug or Flask responsability? The error from the OP comment is raised from Why does the same code work when using IMO, if Werkzeug is suposed to allow using a string value in PS: I could make a PR in both repositories if needed. I'm asking because you are maintainers of both projects and I think both projects deserve a good solution 👌 |
I think it would be good to do this check in Werkzeug's make_server such that it is independent of reloader.
…On 25 March 2017 00:59:46 CET, Antonio Ossa ***@***.***> wrote:
@untitaker, @ThiefMaster
Reading the source code, I thought, **is this Werkzeug or Flask
responsability?** The error from the OP comment is raised from
`werkzeug.serving`, because `run_simple` is from that module. We could
check types after
[flask/app.py#L843](https://github.com/pallets/flask/blob/master/flask/app.py#L843)
to avoid this problem without relying in Werkzeug. But we have another
option: apply the same check at the top of `run_simple`
([werkzeug/serving.py#L602](https://github.com/pallets/werkzeug/blob/master/werkzeug/serving.py#L602))
to (also) avoid the same error when using Werkzeug but not Flask.
**Why does the same code work when using `debug=False`?** Because debug
mode uses the reloader (so [`use_reloader` is set to
`True`](https://github.com/pallets/werkzeug/blob/master/werkzeug/serving.py#L701))
and Werkzeug tries to [use a socket without explicitly converting
`port` to
`int`](https://github.com/pallets/werkzeug/blob/master/werkzeug/serving.py#L717).
When using `debug=False`, `use_reloader` is `False` and Werkzeug [calls
an inner function that uses
`make_server`](https://github.com/pallets/werkzeug/blob/master/werkzeug/serving.py#L693).
The difference in this behaviour is because [`BaseWSGIServer` uses
`int(port)`](https://github.com/pallets/werkzeug/blob/master/werkzeug/serving.py#L501),
explicitly converting the `port` from `str` to `int`.
IMO, if Werkzeug is suposed to allow using a string value in `port`
then we should explicitly convert the `port` parameter, when possible,
and raise an exception when needed. If Werkzeug is not supposed to
allow this behaviour, then Flask should allow `int`s only (and Werkzeug
should do it too)
---
PS: I could make a PR in both repositories if needed. I'm asking
because you are maintainers of both projects and I think both projects
deserve a good solution 👌
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#2220 (comment)
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
But the problem is not in |
Right, forgot about that! |
* Check port parameter type at run_simple Ports should be integers, so a type check is explicitly added to raise an exception when this is ignored. This inappropiate behaviour was detected when using `debug=True` in a Flask application, because a string is accepted and works when it should fail. Closes pallets/flask#2220 Signed-off-by: Antonio Ossa <[email protected]> * Add testcase for pallets/flask#2220 This testcase tries to use a string as port parameter, which should not be allowed by `run_simple`. The test uses `run_simple` directly because the tests configuration raises the error in a different process without giving a chance to catch the `TypeError` exception. See pallets/flask#2220 Signed-off-by: Antonio Ossa <[email protected]> * Add PR #1088 to Changelog Signed-off-by: Antonio Ossa <[email protected]>
Inappropriate behaviour in app.run function with debug set to True and False
app.run(port='5000', debug=False)
runs perfectlyhowever when debug=True
app.run(port='5000', debug=True)
it throws errorThe text was updated successfully, but these errors were encountered: