mysql_pilot Posted December 3, 2023 Posted December 3, 2023 Hi, firstly can I use Python on shared hosting? I don't see it installed on the software section of Cpanel. Reading through the forums I saw it was an option at one time, and I'd like to know if that's still the case. I have two Python files installed in my cgi-bin, permissions were set to 755 when I initially sent out a help ticket earlier today, however I noticed now that permissions are set to 644 after speaking with the technician. One file is saved as .cgi and one is .py, both contain the same script. My skill level is beginner and I'm trying my best to connect a mailing list form to a mysql database. My database is setup, and according to the technician my credentials supplied were working and there was a successful connection when he attempted using them with a php script. Here is my script, with placeholders for the actual credentials. from flask import Flask, request, jsonify import mysql.connector app = Flask(__name__) # MySQL database connection db = mysql.connector.connect( host="/home/xxxxxxx", user="xxxxxxx_test", password="xxxxxxx123", database="xxxxxxx_newsletter_list" ) cursor = db.cursor() @app.route('/subscribe', methods=['POST']) def subscribe(): data = request.json first_name = data['firstName'] email = data['email'] # Insert data into the database cursor.execute("INSERT INTO subscribers (first_name, email) VALUES (%s, %s)", (first_name, email)) db.commit() return jsonify({"message": "Subscription successful!"}) if __name__ == '__main__': app.run(debug=False) I would like to use environment variables, however firstly it would be nice to see if I can make the basic newsletter signup form function. Doing some research, I also discovered maybe there should be a shebang line used, i.e. #!/usr/bin/env python3, and at this point I'm not even smart enough to know if that shebang line should be altered with my credentials where the usr segment is located. Any thoughts appreciated. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.