Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么我会得到“预期的缩进块”?_Python_Mysql - Fatal编程技术网

Python 为什么我会得到“预期的缩进块”?

Python 为什么我会得到“预期的缩进块”?,python,mysql,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',

我正在尝试使用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();
运行此代码时,我得到
预期的缩进块


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

你的第一行不应该有足够的空间来引导它

使用open(“file.txt…时,
后面的行都应该缩进


但您也有断字符串…在您的execute语句中

@GreenChili,请不要修复OP的缩进。您刚刚解决了问题。@MorganThrapp是的,您是对的,回滚了。噢,该死,现在我需要再次大写我的答案:p(只是开玩笑)另外请注意,注意大小写已更改。软化了语音。字符串中的引号无效。您需要选择用于保存查询字符串的引号(“”或“”),并将另一个引号用于值PYTHON(将由数据库解释)。至少在MySQL中,选择是任意的。