Hello i am trying to create a flask app. i am facing problem where datatype of 'result' is none but 'result[0]' is a string.
Code:
def fetch_file(self,token): with self.connect() as db: try: cursor = db.cursor() cursor.execute("SELECT Exten FROM FILE_SHARE WHERE TOKEN = ?;",(token,)) result = cursor.fetchone() return result except s.Error as e: return chalk.red(f"Error fetching file extention for token: {token}")
Flask app:
@app.route("/<token>")def disp(token): exten = dbmgr.fetch_file(token) print(exten[0]) flnm = f"./uploads/{token+'.'+exten[0]}" if os.path.isfile(flnm): return send_file(flnm) else: return "nope"
what should have happened: if i visit example.com/MZ it should have fetched the extension of file(which is png in this case) and then display the file in the browser.
what's happening: Everything works fine but it still gives this error:
print(exten[0]) ^^^^^^^^^TypeError: 'NoneType' object is not subscriptable
print(exten[0]) prints png in my console but still gives the above error.