试图选择从数据库的一些信息,我有一个数据库管理器类,看起来像这样:MYSQLdb/Python - 并非所有在字符串格式化错误期间转换的参数?
class DatabaseManager:
def __init__(self):
self.connection = MySQLdb.connect(host="localhost",
user="neal",
passwd="hacker123",
db="massive")
self.cursor = self.connection.cursor()
当试图做一个选择是这样的:
db = DatabaseManager()
db.cursor.execute("SELECT password FROM USERS WHERE apikey = %s", str(request.apikey))
我得到一个
TypeError: not all arguments converted during string formatting
这很奇怪,因为我有类似的查询在其他地方工作正常,像这样:
db.cursor.execute('''INSERT into USERS(email, username, password, apikey) values (%s, %s, %s, %s)''',
(request.email, request.username, request.password, apikey))
我做错了吗?
编辑:列混乱,表看起来像这样:
CREATE TABLE users (
id int NOT NULL AUTO_INCREMENT,
email varchar(255) NOT NULL,
username varchar(25) NOT NULL,
password varchar(25) NOT NULL,
apikey varchar(45) NOT NULL,
PRIMARY KEY (id),
UNIQUE(email),
UNIQUE(username),
UNIQUE(apikey)
);
您是否尝试将参数作为单个字符串传递给tu9le? – 2014-11-04 19:20:35