Hello I am trying to create api using flask but i am facing issue where sqlite is not saving data. here is the code below:
def data_insert(link):
try:
c.execute(f"INSERT INTO ping(links) VALUES ('{link}');")
conn.commit()
return "sucess"
except sqlite3.DatabaseError as e:
print("AN ERROR HAS OCCURED")
print(chalk.red(e))
return "an internal error has occured."
def get_links():
try:
links = c.fetchall()
print(f"links:{links}")
return links
except sqlite3.DatabaseError or sqlite3.DataError as e:
print(chalk.red(e))
return "an internal error has occured."
and in flask.py:
@app.route("/submit-url")
def main():
url = request.args.get("url")
if url == None:
return "please enter url",404
else:
output = db.data_insert(url)
links = db.get_links()
print(links)
return output
What should have happened: terminal should show list of data what actually happened: It returns empty list.