Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 19054

SQLITE3: printing result gives none but doing same for result[0] gives the result

$
0
0

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.


Viewing all articles
Browse latest Browse all 19054

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>