请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

unindent does not match any outer indentation level

[root@centos-01 python]# cat test001.py 
#coding=utf-8
import MySQLdb

class MysqlSearch(object):

	def __init__(self):
		self.get_conn()
#获取连接
    
    def get_conn(self):
		try:
		    self.conn = MySQLdb.connect(
			    host='127.0.0.1',
			    user='root',
			    passwd='123456',
			    db='news',
			    port=3306,
			    charset='utf8'


		    )
		except MySQLdb.Error as e:
		     print('Error: %s' % e)

	def get_one(self):
		sql = 'SELECT * FROM `news` where `types` = %s order by `created_at` DESC;'
		cursor = self.conn.cursor()
		cursor.execute(sql, ('百家', ))
		rest = cursor.fetchone()
		print(rest)
		cursor.close()
		self.close_conn()




	def close_conn(self):
        try:
            if self.conn:
                # 关闭链接
                self.conn.close()
        except MySQLdb.Error as e:
            print('Error: %s' % e)


def main():
	obj = MysqlSearch()
	obj.get_one()

if __name__ == '__main__':
	main()

[root@centos-01 python]# python test001.py
File “test001.py”, line 10
def get_conn(self):
^
IndentationError: unindent does not match any outer indentation level
我是直接在 centos7 下直接运行的, 一直报这个错误, 不知道什么原因

正在回答 回答被采纳积分+3

1回答

提问者 weixin_慕九州6285195 2019-06-04 16:37:41

好像已经可以了, 换了一个IDE ,还是格式的原因

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号