Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Occasional Flask server error: 'RuntimeError: maximum recursion depth exceeded while calling a Python object'

Tags:

python

flask

I'm trying to figure out what causes this error when I run my app using the basic Flask server during development. I start it with this:

from myapp import app
app.run(debug=True, port=5001)

All is well and I'll continue to code and refresh etc, but then after a while I get the recursion error and have to Ctrl-C the server and restart it. Not a big deal, just a little annoying to have to deal with every now and then.

Here's the full traceback, which I tried to use to determine the cause but can't see anything that stands out (possibly something to do with how werkzeug uses Cookie.py?):

Traceback (most recent call last):
  File "/Users/jeff/.virtualenvs/fmll/lib/python2.7/site-packages/flask/app.py", line 1701, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/jeff/.virtualenvs/fmll/lib/python2.7/site-packages/werkzeug/wsgi.py", line 411, in __call__
    return self.app(environ, start_response)
  (last bit repeated a bunch - trimmed to fit in posting size requirements)
  File "/Users/jeff/.virtualenvs/fmll/lib/python2.7/site-packages/flask/app.py", line 1685, in wsgi_app
    with self.request_context(environ):
  File "/Users/jeff/.virtualenvs/fmll/lib/python2.7/site-packages/flask/ctx.py", line 274, in __enter__
    self.push()
  File "/Users/jeff/.virtualenvs/fmll/lib/python2.7/site-packages/flask/ctx.py", line 238, in push
    self.session = self.app.open_session(self.request)
  File "/Users/jeff/.virtualenvs/fmll/lib/python2.7/site-packages/flask/app.py", line 792, in open_session
    return self.session_interface.open_session(self, request)
  File "/Users/jeff/.virtualenvs/fmll/lib/python2.7/site-packages/flask/sessions.py", line 191, in open_session
    secret_key=key)
  File "/Users/jeff/.virtualenvs/fmll/lib/python2.7/site-packages/werkzeug/contrib/securecookie.py", line 309, in load_cookie
    data = request.cookies.get(key)
  File "/Users/jeff/.virtualenvs/fmll/lib/python2.7/site-packages/werkzeug/utils.py", line 77, in __get__
    value = self.func(obj)
  File "/Users/jeff/.virtualenvs/fmll/lib/python2.7/site-packages/werkzeug/wrappers.py", line 418, in cookies
    cls=self.dict_storage_class)
  File "/Users/jeff/.virtualenvs/fmll/lib/python2.7/site-packages/werkzeug/http.py", line 741, in parse_cookie
    cookie.load(header)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/Cookie.py", line 632, in load
    self.__ParseString(rawdata)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/Cookie.py", line 665, in __ParseString
    self.__set(K, rval, cval)
  File "/Users/jeff/.virtualenvs/fmll/lib/python2.7/site-packages/werkzeug/_internal.py", line 290, in _BaseCookie__set
    morsel = self.get(key, _ExtendedMorsel())
  File "/Users/jeff/.virtualenvs/fmll/lib/python2.7/site-packages/werkzeug/_internal.py", line 271, in __init__
    Morsel.__init__(self)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/Cookie.py", line 438, in __init__
    dict.__setitem__(self, K, "")
RuntimeError: maximum recursion depth exceeded while calling a Python object
like image 991
jeffff Avatar asked Nov 13 '22 13:11

jeffff


1 Answers

Since it occurs during your developement process, you could increase recursion limit, before starting your server, using :

sys.setrecursionlimit(2000) # Choose the right figure for you here
# the value on my system is 1000 but this is platform-dependant

However, you should use it very carefully and probably not in production unless you have a good knowledge of it's impacts.

Ref : http://docs.python.org/2/library/sys.html#sys.setrecursionlimit

like image 104
Y__ Avatar answered Nov 15 '22 05:11

Y__