MySQL python连接器:“并非在字节格式化期间转换了所有参数" [英] MySQL python connector: "not all arguments converted during bytes formatting"

查看:61
本文介绍了MySQL python连接器:“并非在字节格式化期间转换了所有参数"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个mysql数据库,其中具有创建会话的f_name,l_name,password email(pk)的用户"表和具有fg_name(pk),email((pk),users.email(FK))和具有电子邮件(pk,user.email(fk)),owner_email(pk,friendgroup.email(fk)),fg_name(pk,friendgroup.fg_name(fk))和表python烧瓶文件的表'member'以下.登录帐户后,我想在聊天中添加一个朋友.我试图通过会话['email']

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:字节格式化期间并非所有参数都已转换

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

推荐答案

python中的常见错误是使用(bar)而不是(bar,)不是元组.

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

尝试:

cursor.execute(find_owned_friendgroups, (user,))

这篇关于MySQL python连接器:“并非在字节格式化期间转换了所有参数"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆