Oct-23-2024, 03:49 AM
Hello Python Community
I'm following a tutorial about a Flask web app and trying to connect to MySQL to display a data list (SELECT ...) when I get this error in runtime when I navigate to the html page. I paste the error text and then the code which tries to connect to the DB.
Any help will be appreciated. Thank you.
Pablo
I'm following a tutorial about a Flask web app and trying to connect to MySQL to display a data list (SELECT ...) when I get this error in runtime when I navigate to the html page. I paste the error text and then the code which tries to connect to the DB.
Error:MySQLdb.OperationalError
MySQLdb.OperationalError: (2026, 'TLS/SSL error: SSL is required, but the server does not support it')
Traceback (most recent call last)
File "C:\Users\PABLO\AppData\Local\Programs\Python\Python313\Lib\site-packages\flask\app.py", line 1498, in __call__
return self.wsgi_app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\PABLO\AppData\Local\Programs\Python\Python313\Lib\site-packages\flask\app.py", line 1476, in wsgi_app
response = self.handle_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\PABLO\AppData\Local\Programs\Python\Python313\Lib\site-packages\flask\app.py", line 1473, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\PABLO\AppData\Local\Programs\Python\Python313\Lib\site-packages\flask\app.py", line 882, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\PABLO\AppData\Local\Programs\Python\Python313\Lib\site-packages\flask\app.py", line 880, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\PABLO\AppData\Local\Programs\Python\Python313\Lib\site-packages\flask\app.py", line 865, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\PABLO\Desktop\sisclientes\main.py", line 24, in index_clientes
conexion = mysql.connection
^^^^^^^^^^^^^^^^
File "C:\Users\PABLO\AppData\Local\Programs\Python\Python313\Lib\site-packages\flask_mysqldb\__init__.py", line 109, in connection
ctx.mysql_db = self.connect
^^^^^^^^^^^^
File "C:\Users\PABLO\AppData\Local\Programs\Python\Python313\Lib\site-packages\flask_mysqldb\__init__.py", line 97, in connect
return MySQLdb.connect(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\PABLO\AppData\Local\Programs\Python\Python313\Lib\site-packages\MySQLdb\__init__.py", line 121, in Connect
return Connection(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\PABLO\AppData\Local\Programs\Python\Python313\Lib\site-packages\MySQLdb\connections.py", line 195, in __init__
super().__init__(*args, **kwargs2)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
MySQLdb.OperationalError: (2026, 'TLS/SSL error: SSL is required, but the server does not support it')
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.
You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:
dump() shows all variables in the frame
dump(obj) dumps all that's known about the object
from flask import Flask, render_template from flask_mysqldb import MySQL app = Flask(__name__) mysql = MySQL() app.config['MYSQL_HOST'] = 'localhost' app.config['MYSQL_PORT'] = 3306 app.config['MYSQL_USER'] = 'root' app.config['MYSQL_PASSWORD'] = 'root' app.config['MYSQL_DB'] = 'Clientes' app.config['CURSORCLASS'] = 'DictCursor' mysql.init_app(app) @app.route('/') def index(): return render_template('index.html') @app.route('/clientes') def index_clientes(): sql = "SELECT * FROM Clientes" conexion = mysql.connection cursor = conexion.cursor() cursor.execute(sql) clientes = cursor.fetchall() conexion.commit() return render_template('modulos/clientes/index.html', clientes=clientes) @app.route('/clientes/create') def create(): return render_template('/modulos/clientes/create.html') if __name__ == '__main__': app.run(debug=True)The DB is created in XAMPP.
Any help will be appreciated. Thank you.
Pablo