日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

python意外缩进引发逻辑错误_python – IndentationError:意外的缩进错误

發布時間:2024/7/19 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python意外缩进引发逻辑错误_python – IndentationError:意外的缩进错误 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我是

Python的新手,我得到這個錯誤:

Traceback (most recent call last):

File "/usr/local/bin/scrapy", line 4, in

execute()

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scrapy/cmdline.py", line 130, in execute

_run_print_help(parser, _run_command, cmd, args, opts)

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scrapy/cmdline.py", line 96, in _run_print_help

func(*a, **kw)

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scrapy/cmdline.py", line 136, in _run_command

cmd.run(args, opts)

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scrapy/commands/crawl.py", line 42, in run

q = self.crawler.queue

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scrapy/command.py", line 31, in crawler

self._crawler.configure()

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scrapy/crawler.py", line 36, in configure

self.spiders = spman_cls.from_settings(self.settings)

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scrapy/spidermanager.py", line 33, in from_settings

return cls(settings.getlist('SPIDER_MODULES'))

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scrapy/spidermanager.py", line 23, in __init__

for module in walk_modules(name):

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scrapy/utils/misc.py", line 65, in walk_modules

submod = __import__(fullpath, {}, {}, [''])

File "/my_crawler/empt/empt/spiders/empt_spider.py", line 59

check_exists_sql = "SELECT * FROM LINKS WHERE link = '%s' LIMIT 1" % item['link']

^

IndentationError: unexpected indent

在這一點代碼:

def parse_item(self, response):

hxs = HtmlXPathSelector(response)

sites = hxs.select('//a[contains(@href, ".mp3")]/@href').extract()

items = [ ]

#for site in sites:

#link = site.select('a/@href').extract()

#print site

for site in sites:

item = EmptItem()

item['link'] = site #site.select('a/@href').extract()

#### DB INSERT ATTEMPT ###

#MySQL Test

#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)

if cursor.rowcount = 0:

#prepare SQL query to insert a record into the db.

sql = "INSERT INTO LINKS ( link ) VALUES ( '%s')" % item['link']

try:

#execute the sql command

cursor.execute(sql)

#commit your changes to the db

db.commit()

except:

#rollback on error

db.rollback()

#fetch a single row using fetchone() method.

#data = cursor.fetchone()

#print "Database version: %s " % data

#disconnect from server

db.close()

### end mysql

items.append(item)

return items?

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的python意外缩进引发逻辑错误_python – IndentationError:意外的缩进错误的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。