試圖選擇從數據庫的一些信息,我有一個數據庫管理器類,看起來像這樣: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