MySQL python connector:“并非所有参数都在字节格式化期间转换”

2024-09-28 03:14:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个mysql数据库,其中“user”表有f\u name,l\u name,password email(pk),通过它创建会话,表“friendgroup”有fg\u name(pk),email((pk),用户.email(FK)和具有电子邮件(pk,用户电子邮件(fk)),所有者电子邮件(pk,friendgroup.email(fk)),fg\u名称(pk,friendgroup.fg\u名称(fk)),以及下面的python flask文件。 登录帐户后,我想在聊天中添加一个朋友。我试图从会话['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

我希望输出将是一个打开的窗口,并在需要时积极使用add friend,但显示错误:

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


Tags: 用户name名称电子邮件emailmysqlfindcursor
1条回答
网友
1楼 · 发布于 2024-09-28 03:14:12

python中的一个常见错误是使用(bar)而不是(bar,),前者不是元组。你知道吗

尝试使用:

cursor.execute(find_owned_friendgroups, (user,))

相关问题 更多 >

    热门问题