python - Flask服务器偶尔报错: 'RuntimeError: maximum recursion depth exceeded while calling a Python object'

标签 python flask

当我在开发过程中使用基本 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

最佳答案

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

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

关于python - Flask服务器偶尔报错: 'RuntimeError: maximum recursion depth exceeded while calling a Python object' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14330256/

相关文章:

python - Flask 和长时间运行的任务

python - Python中的类变量和实例变量问题

Python 正则表达式 : matching a parenthesis within parenthesis

python - Flask app.add_url_rule 装饰器错误

python - 如何使用flask在多个页面中显示用户名?

python - 导入后找不到模块

python - Flask-SQLAlchemy backref 函数和 backref 参数

python - sympylambdaify 添加两个函数

python - 将多个 Python 子解释器嵌入到 C 程序中

python - 日志记录关闭 flask 终端输出