我遇到了致命的问题:flask应用程序中出现stackoverflow错误。它发生在特定功能中,但似乎指向app.run语句。包含错误的函数是这样的:
@login_required
@flask_app.route('/newgame', methods=['GET', 'POST'])
def newGame():
user = current_user
game_form = NewBetForm()
if game_form.is_submitted():
player = user.address
privKey = user.privKey
ethPwd = user.ethPwd
amt = game_form.amount.data
team_name = game_form.teamName.data
player2 = game_form.player2.data
player2team = game_form.player2Team.data
user2 = dbsession.query(User).filter_by(username=player2).first()
try:
contract = createBet(player,user2.address,amt,privKey,ethPwd)
contract.functions.createPlayer(w3.toChecksumAddress(player),amt,team_name).call()
game = Game(player1=player,player1_team=team_name,
player2_team=player2team,addr=contract.address,active=True,amount=amt)
invite = Invite(player1_from=user,player2_to=user2,game_id=game,amount=amt,team=player2team)
dbsession.add(invite)
dbsession.commit()
dbsession.add(game)
dbsession.commit()
flash("Successfully entered bet game")
return redirect(url_for('viewGame', game_id=game.id))
except:
flash("There was an issue with this bet. Please try again")
return redirect(url_for('newGame'))
return render_template('games/new_game.html', form=game_form)
我得到的错误的最后一行(完整的堆栈跟踪将在本文后面)是
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/flask/app.py", line 943 in run
File "app.py", line 6 in <module>
我在哪里看到它指向app.py文件第6行上的app.run语句:
flask_app.run(debug=True,host='localhost',threaded=True,port=port)
我不确定错误实际上是在哪里发生的-对我来说run语句会引起stackoverflow错误是没有意义的。下面是完整的错误跟踪:
Current thread 0x0000700000a04000 (most recent call first):
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/sql/util.py", line 406 in trunc
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/sql/util.py", line 521 in <genexpr>
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/sql/util.py", line 521 in _repr_params
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/sql/util.py", line 484 in __repr__
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/exc.py", line 352 in _sql_message
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/exc.py", line 76 in __str__
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 294 in _assert_active
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 407 in _connection_for_bind
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 1129 in _connection_for_bind
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 1123 in connection
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3286 in _connection_from_session
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3308 in _get_bind_args
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3293 in _execute_and_instances
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3271 in __iter__
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3198 in one_or_none
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3229 in one
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/loading.py", line 282 in load_on_pk_identity
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/loading.py", line 208 in load_on_ident
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/loading.py", line 979 in load_scalar_attributes
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/state.py", line 660 in _load_expired
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/loading.py", line 182 in get_from_identity
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 987 in _identity_lookup
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 1012 in _get_impl
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 933 in get
File "/Users/pasquarella4292/Documents/newbet/app/pyapp/models.py", line 48 in load_user
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/flask_login/login_manager.py", line 321 in reload_user
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/flask_login/login_manager.py", line 359 in _load_user
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/flask_login/utils.py", line 335 in _get_user
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/flask_login/utils.py", line 26 in <lambda>
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/werkzeug/local.py", line 306 in _get_current_object
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/werkzeug/local.py", line 321 in __repr__
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/sql/util.py", line 406 in trunc
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/sql/util.py", line 521 in <genexpr>
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/sql/util.py", line 521 in _repr_params
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/sql/util.py", line 484 in __repr__
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/exc.py", line 352 in _sql_message
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/exc.py", line 76 in __str__
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 294 in _assert_active
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 407 in _connection_for_bind
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 1129 in _connection_for_bind
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 1123 in connection
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3286 in _connection_from_session
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3308 in _get_bind_args
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3293 in _execute_and_instances
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3271 in __iter__
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3198 in one_or_none
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3229 in one
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/loading.py", line 282 in load_on_pk_identity
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/loading.py", line 208 in load_on_ident
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/loading.py", line 979 in load_scalar_attributes
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/state.py", line 660 in _load_expired
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/attributes.py", line 677 in get
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/attributes.py", line 276 in __get__
File "/Users/pasquarella4292/Documents/newbet/app/pyapp/models.py", line 38 in __repr__
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/sql/util.py", line 406 in trunc
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/sql/util.py", line 521 in <genexpr>
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/sql/util.py", line 521 in _repr_params
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/sql/util.py", line 484 in __repr__
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/exc.py", line 352 in _sql_message
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/exc.py", line 76 in __str__
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 294 in _assert_active
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 407 in _connection_for_bind
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 1129 in _connection_for_bind
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 1123 in connection
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3286 in _connection_from_session
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3308 in _get_bind_args
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3293 in _execute_and_instances
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3271 in __iter__
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3198 in one_or_none
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3229 in one
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/loading.py", line 282 in load_on_pk_identity
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/loading.py", line 208 in load_on_ident
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/loading.py", line 979 in load_scalar_attributes
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/state.py", line 660 in _load_expired
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/loading.py", line 182 in get_from_identity
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 987 in _identity_lookup
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 1012 in _get_impl
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 933 in get
File "/Users/pasquarella4292/Documents/newbet/app/pyapp/models.py", line 48 in load_user
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/flask_login/login_manager.py", line 321 in reload_user
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/flask_login/login_manager.py", line 359 in _load_user
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/flask_login/utils.py", line 335 in _get_user
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/flask_login/utils.py", line 26 in <lambda>
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/werkzeug/local.py", line 306 in _get_current_object
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/werkzeug/local.py", line 321 in __repr__
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/sql/util.py", line 406 in trunc
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/sql/util.py", line 521 in <genexpr>
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/sql/util.py", line 521 in _repr_params
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/sql/util.py", line 484 in __repr__
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/exc.py", line 352 in _sql_message
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/exc.py", line 76 in __str__
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 294 in _assert_active
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 407 in _connection_for_bind
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 1129 in _connection_for_bind
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 1123 in connection
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3286 in _connection_from_session
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3308 in _get_bind_args
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3293 in _execute_and_instances
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3271 in __iter__
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3198 in one_or_none
...
Thread 0x0000700000501000 (most recent call first):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/selectors.py", line 376 in select
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socketserver.py", line 236 in serve_forever
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/werkzeug/serving.py", line 612 in serve_forever
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/werkzeug/serving.py", line 777 in inner
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/threading.py", line 864 in run
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/threading.py", line 916 in _bootstrap_inner
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/threading.py", line 884 in _bootstrap
Thread 0x00007fff754cd000 (most recent call first):
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/werkzeug/_reloader.py", line 164 in run
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/werkzeug/_reloader.py", line 273 in run_with_reloader
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/werkzeug/serving.py", line 812 in run_simple
File "/Users/pasquarella4292/.local/share/virtualenvs/newbet-EG4I_zLE/lib/python3.6/site-packages/flask/app.py", line 943 in run
File "app.py", line 6 in <module>
编辑
显示load_user方法:
@login.user_loader
def load_user(id):
return dbsession.query(User).get(int(id))