TypeError: write() argument must be str, not tuple when trying to fetch data from the mysql db

Viewed 544

I am getting type error in Flask, saying:

TypeError: write() argument must be str, not tuple when trying to fetch data from the mysql db using python

Here is the part of the code

if request.form.get('Body') == "SRE1":

   advert = mysql.connection.cursor()
   advert.execute("SELECT message FROM data1 WHERE code='SRE1' ")
    
   myresult = advert.fetchall()
    
   for row in myresult:

       resp.message(row)
       return str(resp)
1 Answers

I think that is the problem: Also if in your query you only SELECT one field (message) when you iterate through your myresult variable, containing all the rows, each row it's considered as an array (obviously an array of size=1 and with only one element: message).
You can easily solve your problem changing this resp.message(row) to this:

resp.message(row[0])
Related