Python RecursionError:调用Python对象时超出了最大递归深度

时间:2017-06-06 05:43:13

标签: python html json forms flask

我一直在尝试使用各种方法修复此错误,但仍然找不到任何错误。我正在做的是从HTML表单中检索2个字符串,然后将其作为JSON发送到我的数据库。这是代码。

HTML表单:

<link rel="stylesheet" href="/static/css/loginstyle.css" type="text/css">
<form action="/registerUser" method="POST">
<div class="login">
    <div class="login-screen">
        <div class="app-title">
            <h1>Register</h1>
        </div>

        <div class="login-form">
            <div class="control-group">
                <input type="text" class="login-field" value="" placeholder="Username" name="username">
                <label class="login-field-icon fui-user" for="login-name"></label>
            </div>

            <div class="control-group">
                <input type="password" class="login-field" value="" placeholder="password" name="password">
                <label class="login-field-icon fui-lock" for="login-pass"></label>
            </div>

            <input type="submit" value="Register" class="btn btn-primary btn-large btn-block">
            <br>
        </div>
    </div>
</div>

Python Flask Code:

sys.setrecursionlimit(1500)
@app.route('/registerUser', methods=['POST'])
def register_user():
  if request.method == 'POST':
   idx = uuid.uuid4()
   uid = str(idx)
   username = request.form['username']
   password = request.form['password']
   password = password.encode('utf-8')
   sha1 = hashlib.sha1()
   sha1.update(password)
   password = sha1.hexdigest()
   data = {'uid': uid, 'username': username, 'password': password}
   db.child("users").child(username).set(data)
   return render_template('/login.html')
  else:
   error = 'What are you trying to do?'
   return render_template('/login.html', error = error)

错误:

  

RecursionError:调用Python对象时超出了最大递归深度

1 个答案:

答案 0 :(得分:0)

通过将python版本更改为较低版本来解决。