Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Werkzeug on Python 3 raises "< not supported between instances of str and int"

I am trying to upgrade my flask app from Python 2.7 to 3.6.

The dev server runs. However when I try to access the home view, I am getting the rather unhelpful error:

INFO:werkzeug:127.0.0.1 - - [29/Aug/2018 14:41:11] "GET / HTTP/1.1" 500 
ERROR:werkzeug:Error on request:
Traceback (most recent call last):
  File "/Users/david/PycharmProjects/med-portal/venv/lib/python3.6/site-packages/werkzeug/serving.py", line 269, in run_wsgi
    execute(self.server.app)
  File "/Users/david/PycharmProjects/med-portal/venv/lib/python3.6/site-packages/werkzeug/serving.py", line 260, in execute
    write(data)
  File "/Users/david/PycharmProjects/med-portal/venv/lib/python3.6/site-packages/werkzeug/serving.py", line 231, in write
    status < 200 or status in (204, 304)):
TypeError: '<' not supported between instances of 'str' and 'int'
# The Home page is accessible to authenticated users
@core_blueprint.route('')
@login_required  # Limits access to authenticated and active users
def home_page():
    print("Return home")
    return render_template('index.html')

Version Info: Flask version 1.0.2, Werkzeug 0.14, Mac OSX High Sierra 10.13.6

like image 205
David Simic Avatar asked Aug 29 '18 19:08

David Simic


2 Answers

This is fixed in werkzeug 0.14.1

See: https://github.com/pallets/werkzeug/commit/86f6d0bc7c410f70ac290eef018ee48a46563d4b

Fixed a regression in the development server

This fixes a type error being thrown for some requests.

like image 199
Zeke Avatar answered Sep 24 '22 15:09

Zeke


It seems you're error is outside of this file, most likely either in your @login_required decorator or in your flask-app using this blueprint.

I think you are returning a status code as a string somewhere e.g. return Response, "200" which is causing werkzeug total the comparison

like image 26
Hultner Avatar answered Sep 24 '22 15:09

Hultner