IndentationError: unexpected indent error

后端 未结 6 1785
太阳男子
太阳男子 2020-12-10 01:49

I am new to Python and am getting this error:

Traceback (most recent call last):
  File \"/usr/local/bin/scrapy\", line 4, in 
    execute()
           


        
6条回答
  •  时光说笑
    2020-12-10 02:03

    The error is pretty straightforward - the line starting with check_exists_sql isn't indented properly. From the context of your code, I'd indent it and the following lines to match the line before it:

       #open db connection
       db = MySQLdb.connect("localhost","root","str0ng","TESTDB")
    
       #prepare a cursor object using cursor() method
       cursor = db.cursor()
    
       #see if any links in the DB match the crawled link
       check_exists_sql = "SELECT * FROM LINKS WHERE link = '%s' LIMIT 1" % item['link']
    
       cursor.execute(check_exists_sql)
    

    And keep indenting it until the for loop ends (all the way through to and including items.append(item).

提交回复
热议问题