0

我正在尝试获取用户信息并添加到数据库。下面的代码在 localhost 中完美运行,但是当我尝试在我的 ec2 实例中执行下面的行时,它给出了 mysql 错误

@app.route('/subscribe', methods=['POST'])
def subscribe():
    if request.method == 'POST':
        # app.logger.debug(request.form['email'])
        # app.logger.debug(request.form['comment'])
        email = request.form['email']
        match = re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', email)
        if match != None:
            post = Subs(request.form['email'], request.form['comment'])
            db_session.add(post)
            db_session.commit()
            return '''
            <script type="text/javascript">
            alert('Subscribed');
            window.location= "/";
            </script>'''
        else:
            return '''
            <script type="text/javascript">
            alert('Enter the right email');
            window.location= "/";
            </script>'''
    else:
        return '''
            <script type="text/javascript">
            alert('Wrong Access');
            window.location= "/";
            </script>'''

和错误信息

[Thu Jul 21 22:33:21.610717 2016] [:error] [pid 3219:tid 140455150794496] [remote 222.98.88.22:48458]   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 801, in commit
[Thu Jul 21 22:33:21.610718 2016] [:error] [pid 3219:tid 140455150794496] [remote 222.98.88.22:48458]     self.transaction.commit()
[Thu Jul 21 22:33:21.610732 2016] [:error] [pid 3219:tid 140455150794496] [remote 222.98.88.22:48458]   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 390, in commit
[Thu Jul 21 22:33:21.610734 2016] [:error] [pid 3219:tid 140455150794496] [remote 222.98.88.22:48458]     self._assert_active(prepared_ok=True)
[Thu Jul 21 22:33:21.610736 2016] [:error] [pid 3219:tid 140455150794496] [remote 222.98.88.22:48458]   File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 214, in _assert_active
[Thu Jul 21 22:33:21.610738 2016] [:error] [pid 3219:tid 140455150794496] [remote 222.98.88.22:48458]     % self._rollback_exception
[Thu Jul 21 22:33:21.610740 2016] [:error] [pid 3219:tid 140455150794496] [remote 222.98.88.22:48458] InvalidRequestError: This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: (_mysql_exceptions.OperationalError) (2013, "Lost connection to MySQL server at 'reading initial communication packet', system error: 0")
[Thu Jul 21 22:42:33.139955 2016] [mpm_event:notice] [pid 1268:tid 140455277680512] AH00494: SIGHUP received.  Attempting to restart
[Thu Jul 21 22:42:33.193978 2016] [mpm_event:notice] [pid 1268:tid 140455277680512] AH00489: Apache/2.4.7 (Ubuntu) mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
[Thu Jul 21 22:42:33.194006 2016] [core:notice] [pid 1268:tid 140455277680512] AH00094: Command line: '/usr/sbin/apache2'
[Thu Jul 21 22:47:52.333109 2016] [core:error] [pid 3466:tid 140454934791936] [client 222.98.88.22:57431] Script timed out before returning headers: kaunotifier.wsgi, referer: http://ec2-52-78-90-136.ap-northeast-2.compute.amazonaws.com/index
[Thu Jul 21 22:47:52.734127 2016] [core:error] [pid 3465:tid 140455052289792] [client 222.98.88.22:57432] Script timed out before returning headers: kaunotifier.wsgi, referer: http://ec2-52-78-90-136.ap-northeast-2.compute.amazonaws.com/index

我不知道如何解决这个问题。

提前致谢。

4

0 回答 0