Код: Выделить всё
from flask import Flask, request
import mysql.connector
db = mysql.connector.connect(
host="*host*",
user="*user*",
password="*password*",
database="*database*"
)
cursor = db.cursor()
app = Flask(__name__)
@app.errorhandler(404)
def page_not_found(e):
return "404
The resource could not be found.
", 404
@app.route('//', methods=['POST'])
def index(date, temperature):
try:
cursor.execute(f"INSERT INTO temperature VALUES ('{date}', {temperature})")
db.commit()
except mysql.connector.Error as error:
print(f"Failed to insert data into MySQL table: {error}")
db.rollback()
return "Data inserted successfully"
@app.route('/addtemperature/', methods=['POST'])
def addtemperature(date, temperature):
data = request.json()
if __name__ == '__main__':
app.run(debug=True, host="0.0.0.0", port=5000 )
Код: Выделить всё
python3 app.py
Код: Выделить всё
Traceback (most recent call last):
File "/Users/daniel/Desktop/Python3/Raspberry Pi Pico/app.py", line 2, in
import mysql.connector
ModuleNotFoundError: No module named 'mysql'
Я также пробовал удалить, а затем переустановить.
Я использую MacOS 15.1.1 ( Секвойя)
Подробнее здесь: https://stackoverflow.com/questions/792 ... 1-python-3
Мобильная версия