2015-12-11 235 views
1

我需要做一個更新,所以我做了這個,但我得到了這個代碼的問題。pymysql更新不起作用

def runUpdate(query, aux): 

#Establecemos la conexion con la base de datos 
connection = pymysql.connect(host='localhost', user='root', password='root', db='influencers', charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) 
try: 
    with connection.cursor() as cursor: 
     #Ejecutar query 
     cursor.execute(query, aux) 
     result = cursor.fetchall() 
     #Guardar cambios conexion 
     connection.commit() 
finally: 
    connection.close() 

它似乎確定,但是當我做了這個:

runUpdate("""UPDATE Influencers SET tweets = '%s' WHERE usuario = '%s'""", (numTweets, user)) 

在這裏引發我一個錯誤:

cursor.execute(query, aux) 

這是一些控制檯文字: (...) return escape_str(value, mapping) File "/Library/Python/2.7/site-packages/pymysql/converters.py", line 71, in escape_str return "'%s'" % escape_string(value, mapping) File "/Library/Python/2.7/site-packages/pymysql/converters.py", line 68, in escape_string lambda match: ESCAPE_MAP.get(match.group(0)), value),)) TypeError: expected string or buffer

我認爲我的語法錯了,但我不明白爲什麼。我正在學Python,所以請好:)

回答