I try to update my sqlite database using flask webhook.
It seems commands line work fine if I type manually in the python console but my flask webhook didn’t update my SQLite database. It seems the apps fail at the “cursor.execute()” line.
here is my webhook code:
JavaScript
x
21
21
1
@app.route('/trendanalyser', methods=['POST'])
2
def trendanalyser():
3
data = json.loads(request.data)
4
if data['passphrase'] == config.WEBHOOK_PASSPHRASE:
5
#Init update variables
6
tastate = data['TrendAnalyser']
7
date_format = datetime.today()
8
date_update = date_format.strftime("%d/%m/%Y %H:%M:%S")
9
update_data = ((tastate), (date_update))
10
#Database connection
11
connection = sqlite3.connect('TAState15min.db')
12
cursor = connection.cursor()
13
#Database Update
14
update_query = """Update TrendAnalyser set state = ?, date = ? where id = 1"""
15
cursor.execute(update_query, update_data)
16
connection.commit()
17
return("Record Updated successfully")
18
cursor.close()
19
else:
20
return {"invalide passphrase"}
21
Can you please tell me what’s wrong with my code ?
if it’s can help, here is my database structure (my db creation):
JavaScript
1
19
19
1
#Database connection
2
conn = sqlite3.connect("TAState15min.db")
3
cursor = conn.cursor()
4
#Create table
5
sql_query = """ CREATE TABLE TrendAnalyser (
6
id integer PRIMARY KEY,
7
state text,
8
date text
9
)"""
10
cursor.execute(sql_query)
11
#Create empty row with ID at 1
12
insert_query = """INSERT INTO TrendAnalyser
13
(id, state, date)
14
VALUES (1, 'Null', 'Null');"""
15
cursor.execute(insert_query)
16
conn.commit()
17
#Close database connexion
18
cursor.close()
19
**I finally found the issue, webhooks need the full path to the SQLite database to work fine. I just start to code in python, it was a noob issue… **
Advertisement
Answer
I finally found the issue, webhooks need the full path to the SQLite database to work fine. I just start to code in python, it was a noob issue…