MySQL python connector: “not all arguments converted during bytes formatting”

浪尽此生 提交于 2020-07-10 08:20:41

问题


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


回答1:


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,))


来源:https://stackoverflow.com/questions/57770914/mysql-python-connector-not-all-arguments-converted-during-bytes-formatting

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!