2

I have a mysql database in which 'user' table having f_name,l_name,password email(pk) by which session is created and table 'friendgroup' having fg_name(pk), email((pk),users.email(FK)) and table 'member' having email(pk,user.email(fk)), owner_email(pk,friendgroup.email(fk)), fg_name(pk,friendgroup.fg_name(fk)), and a python flask file below. After login account, I wish to add a friend in chat. I tried to fix it from session['email']

def add_friend():
    user = session['email']
    friendgroups = _get_own_friendgroups(user) return 
    render_template('addFriend.html', friendgroups=friendgroups)
def _get_own_friendgroups(user):
    cursor = mysql.connection.cursor()
    #find all friendgroups that the user owns
    find_owned_friendgroups = 'SELECT fg_name, description FROM friendgroup WHERE owner_email = %s  ORDER BY fg_name ASC'
    cursor.execute(find_owned_friendgroups, (user))
    owned_friendgroups = cursor.fetchall()
    cursor.close()
    return owned_friendgroups

I expect output will be an open window and actively use of add friend when needed but showing error:

MySQLdb._exceptions.ProgrammingError: not all arguments converted during bytes formatting

3
  • Consider changing the title to summarize the specific problem. Commented Sep 3, 2019 at 11:54
  • thanks for the suggestion, I'm new on stackflow please suggest me answer also Commented Sep 3, 2019 at 11:55
  • No problem, I think you should mention that the problem concerns the MySQL connector with the error "not all arguments converted during bytes formatting". Commented Sep 3, 2019 at 11:58

1 Answer 1

3

A common error in python is to use (bar) instead of (bar,) the former not being a tuple.

Try with:

cursor.execute(find_owned_friendgroups, (user,))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.