为什么我得到'预期缩进块'?

时间:2015-09-23 18:44:49

标签: python mysql

我正在尝试用Python将图像插入MySQL。

 import mysql.connector
import base64

conn = mysql.connector.Connect(user="root",passwd="solomon",host="localhost",db="binarymanipulation",port="3306")

cursor =conn.cursor;
with open('/home/solomon/Downloads/javapic.jpeg', 'rb') as image:

cursor.execute('INSERT INTO images(id,size,image) VALUES('PYTHON',245,image) ')
conn.commit();
conn.close();

我在运行此代码时收到expected an indented block

我错过了什么?什么是正确的方法?

1 个答案:

答案 0 :(得分:2)

你的第一行不应该有空间来领导它

with open("file.txt...后的所有行都应缩进

但是你的执行语句

中也有破碎的字符串