Forums

Flask-MySQLdb

Hi Guys,

I am having trouble with getting through this "Internal Server Error (500)", and I think that is because I am using flask-mysqldb as my way to connect to my database. I was using phpmyadmin before I migrated everything to pythonanywere and was working fine. I was using the localhost and local settings for the connection to MySQL. And now, it's giving me an error.

Here is the log for the error:

[2017-06-02 13:22:29,470] ERROR in app: Exception on / [POST]
2017-06-02 13:22:29,475: Traceback (most recent call last):
2017-06-02 13:22:29,475:   File "/home/mindservation/.virtualenvs/flask_web/local/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
2017-06-02 13:22:29,475:     response = self.full_dispatch_request()
2017-06-02 13:22:29,475:   File "/home/mindservation/.virtualenvs/flask_web/local/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
2017-06-02 13:22:29,475:     rv = self.handle_user_exception(e)
2017-06-02 13:22:29,475:   File "/home/mindservation/.virtualenvs/flask_web/local/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
2017-06-02 13:22:29,475:     reraise(exc_type, exc_value, tb)
2017-06-02 13:22:29,475:   File "/home/mindservation/.virtualenvs/flask_web/local/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
2017-06-02 13:22:29,476:     rv = self.dispatch_request()
2017-06-02 13:22:29,476:   File "/home/mindservation/.virtualenvs/flask_web/local/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
2017-06-02 13:22:29,476:     return self.view_functions[rule.endpoint](**req.view_args)
2017-06-02 13:22:29,476:   File "/home/mindservation/mysite/main.py", line 208, in index
2017-06-02 13:22:29,476:     cur = mysql.connection.cursor()
2017-06-02 13:22:29,476:   File "/home/mindservation/.virtualenvs/flask_web/local/lib/python2.7/site-packages/flask_mysqldb/__init__.py", line 94, in connection
2017-06-02 13:22:29,477:     ctx.mysql_db = self.connect
2017-06-02 13:22:29,477:   File "/home/mindservation/.virtualenvs/flask_web/local/lib/python2.7/site-packages/flask_mysqldb/__init__.py", line 81, in connect
2017-06-02 13:22:29,477:     return MySQLdb.connect(**kwargs)
2017-06-02 13:22:29,477:   File "/home/mindservation/.virtualenvs/flask_web/local/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
2017-06-02 13:22:29,477:     return Connection(*args, **kwargs)
2017-06-02 13:22:29,477:   File "/home/mindservation/.virtualenvs/flask_web/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 193, in __init__
2017-06-02 13:22:29,478:     super(Connection, self).__init__(*args, **kwargs2)
2017-06-02 13:22:29,478: TypeError: an integer is required

Here is the link to Flask-MySQLdb = http://flask-mysqldb.readthedocs.io/en/latest/

Does the error say something about the 500 server error? I get the error whenever I try to use the form.

Here's my site: http://mindservation.pythonanywhere.com/

I am sure I have provided the corrected information for the MySQL properties(host, username, etc...)

Can you please advice? Please and thanks.

[edit by admin: formatting]

Hi there -- I sent you an email about this, but perhaps it didn't get through. I think the problem is that you're specifying the MySQL port as a string, and it should be an integer. That is, your code says

app.config['MYSQL_PORT'] = '3306'

...when it should be this:

app.config['MYSQL_PORT'] = 3306