Python 在回溯中,我的烧瓶代码出现了无法解释的键错误

Python 在回溯中,我的烧瓶代码出现了无法解释的键错误,python,flask,neo4j,Python,Flask,Neo4j,这只虫子快把我逼疯了。我正在尝试使用flask用python创建一个网站的后端。我得到以下错误和回溯: KeyError KeyError: 'person_id' Traceback (most recent call last) This is the Copy/Paste friendly version of the traceback. You can also paste this traceback into a gist: Traceback (most recent ca

这只虫子快把我逼疯了。我正在尝试使用flask用python创建一个网站的后端。我得到以下错误和回溯:

KeyError

KeyError: 'person_id'
Traceback (most recent call last)

This is the Copy/Paste friendly version of the traceback. You can also paste this traceback into a gist:

Traceback (most recent call last):
  File "/home/antonina/Desktop/ant/neo4j-flask/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/antonina/Desktop/ant/neo4j-flask/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/home/antonina/Desktop/ant/neo4j-flask/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/antonina/Desktop/ant/neo4j-flask/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/antonina/Desktop/ant/neo4j-flask/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/antonina/Desktop/ant/neo4j-flask/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/antonina/Desktop/ant/neo4j-flask/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/antonina/Desktop/ant/neo4j-flask/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/antonina/Desktop/ant/nic/blog/views.py", line 310, in family_tree
    subject_id = session['person_id']
  File "/home/antonina/Desktop/ant/neo4j-flask/lib/python2.7/site-packages/werkzeug/local.py", line 377, in <lambda>
    __getitem__ = lambda x, i: x._get_current_object()[i]
KeyError: 'person_id'
KeyError

KeyError: 'person_id'
Traceback (most recent call last)

    File "/home/antonina/Desktop/ant/neo4j-flask/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__

    return self.wsgi_app(environ, start_response)

    File "/home/antonina/Desktop/ant/neo4j-flask/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app

     [Open an interactive python shell in this frame] response = self.handle_exception(e)

    File "/home/antonina/Desktop/ant/neo4j-flask/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception

    reraise(exc_type, exc_value, tb)

    File "/home/antonina/Desktop/ant/neo4j-flask/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app

    response = self.full_dispatch_request()

    File "/home/antonina/Desktop/ant/neo4j-flask/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request

    rv = self.handle_user_exception(e)

    File "/home/antonina/Desktop/ant/neo4j-flask/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception

    reraise(exc_type, exc_value, tb)

    File "/home/antonina/Desktop/ant/neo4j-flask/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request

    rv = self.dispatch_request()

    File "/home/antonina/Desktop/ant/neo4j-flask/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request

    return self.view_functions[rule.endpoint](**req.view_args)

    File "/home/antonina/Desktop/ant/nic/blog/views.py", line 310, in family_tree

    subject_id = session['person_id']

    File "/home/antonina/Desktop/ant/neo4j-flask/lib/python2.7/site-packages/werkzeug/local.py", line 377, in <lambda>

    __getitem__ = lambda x, i: x._get_current_object()[i]

    KeyError: 'person_id'

session.get('person\u id',-1)
TypeError:'SecureCookieSession'对象不可调用。文件“/home/antonina/Desktop/ant/nic/blog/views.py”,第310行,在族树subject\u id=session('person\u id',-1)TypeError:'SecureCookieSession'对象不可调用not
session('person\u id',-1)
。。。您应该使用
debug=True
运行flask应用程序,在出现错误页面时打开终端,查看什么是
session
,什么是
session.get
(它应该是一个函数…)(因此在flask的错误页面上,单击看起来像计算机的小图标(或者可能只是一个计算机提示)要在错误页面上直接进入交互式调试…并尝试打印会话etc
>>会话
。。。
@app.route('/family_tree', methods=['GET','POST'])
def family_tree():
    subject_id = session['person_id']
    if request.method == 'POST':
        if request.form['Select'] != 'RETURN' :
            subject_id = request.form['Select']
            if(subject_id == 'Not_registered') :
                subject_id = session['person_id']
        else :
            return redirect(url_for('person'))

    father = mother = ['Not_registered','Not_registered','Not_registered','Not_registered','Not_registered','Not_registered']
    siblings = []
    mother_node, father_node = Person(subject_id).get_parents()
    if (mother_node) :
        mother_id = (mother_node[0]['mother.person_id'])
        mother = mother_id.split(';')
        mother.append(mother_id)
        mother.append(get_prof_pic(mother_id))
        for sibling in Person(mother_id).get_children_mother() :
            if sibling not in siblings and sibling != None and sibling['person.person_id'] != subject_id :
                siblings.append(sibling)

    if (father_node) :
        father_id = (father_node[0]['father.person_id'])
        father = father_id.split(';')
        father.append(father_id)
        father.append(get_prof_pic(father_id))
        for sibling in Person(father_id).get_children_father() :
            if sibling not in siblings and sibling != None and sibling['person.person_id'] != subject_id :
                siblings.append(sibling)

    subject = subject_id.split(';')
    subject.append(subject_id)
    subject.append(get_prof_pic(subject_id))
    sibling_list = []
    for sibling in siblings :
        tmp = sibling['person.person_id'].split(';')
        tmp.append(sibling['person.person_id'])
        tmp.append(get_prof_pic(sibling['person.person_id']))
        sibling_list.append(tmp)

    children_f = Person(subject_id).get_children_father()
    children_m = Person(subject_id).get_children_mother()
    child_list = []
    children = []

    for child in children_f:
        if child not in children and child != None :
            children.append(child)

    for child in children_m:
        if child not in children and child != None :
            children.append(child)

    for child in children :
        tmp = child['person.person_id'].split(';')
        tmp.append(child['person.person_id'])
        tmp.append(get_prof_pic(child['person.person_id']))
        child_list.append(tmp)


    return render_template('family_tree.html',
                           subject=subject,
                           mother=mother,
                           father=father,
                           sibling_list=sibling_list,
                           child_list=child_list
                           )