0

I am trying to get users info and add to database. The code below works perfect in localhost but when I try to execute line below in my ec2 instance, it gives error with 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>'''

and the error message

[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

I have no idea how to solve this problem.

Thanks in advance.

  • Are you connecting to the same instance of MySQL both locally and on EC2? If not, are you sure the credentials being used on EC2 work and that the database is accepting connections? – dirn Jul 21 '16 at 14:10
  • @dirn I am using an mysql instance only in EC2. How can I check that the credentials being used on EC2 work and that the database is accepting connections? – leaving_traces Jul 21 '16 at 14:12
  • `mysql databasename -h hostname -u username -p` or [something along those lines](http://dev.mysql.com/doc/refman/5.5/en/mysql.html). – dirn Jul 21 '16 at 14:41
  • @dirn Thank you problem solved – leaving_traces Jul 23 '16 at 08:34

0 Answers0