5

我试图找出在开发期间使用基本 Flask 服务器运行我的应用程序时导致此错误的原因。我从这个开始:

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

一切都很好,我将继续编码和刷新等,但过了一会儿我得到递归错误,必须按 Ctrl-C 重新启动服务器。没什么大不了的,只是时不时地处理起来有点烦人。

这是完整的回溯,我试图用它来确定原因,但看不到任何突出的东西(可能与 werkzeug 使用 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
4

1 回答 1

1

由于它发生在您的开发过程中,您可以在启动服务器之前增加递归限制,使用:

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

但是,您应该非常小心地使用它,除非您充分了解它的影响,否则可能不会在生产中使用它。

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

于 2013-02-05T13:49:56.030 回答