python - 關於Scrapy中TwistedPipline報錯
给我你的怀抱
给我你的怀抱 2017-05-18 10:56:26
0
1
621
> python3.5 / pycharm 

crawlspider 回傳的 item 是絕對沒有問題的,接上TwistedPipline就報錯 請哪位老師幫忙分析下報錯程式碼

# TwistedPipline
class MysqlTwistedPipline(object):
    def __init__(self, dbpool):
        self.dbpool = dbpool

    @classmethod
    def from_settings(cls, settings):
        dbparms = dict(
            host = settings["MYSQL_HOST"],
            db = settings["MYSQL_DBNAME"],
            user = settings["MYSQL_USER"],
            passwd = settings["MYSQL_PASSWORD"],
            charset='utf8',
            cursorclass=MySQLdb.cursors.DictCursor,
            use_unicode=True,
        )
        dbpool = adbapi.ConnectionPool("MySQLdb", **dbparms)

        return cls(dbpool)

    def process_item(self, item, spider):
        query = self.dbpool.runInteraction(self.do_insert, item)
        query.addErrback(self.handle_error, item, spider) 

    def handle_error(self, failure, item, spider):
        print (failure)

    def do_insert(self, cursor, item):
        insert_sql, params = item.insert_values()
        print (insert_sql, params)
        cursor.execute(insert_sql, params)
        return item
        

Error code

2017-05-01 00:06:16 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.lagou.com/jobs/2108656.html> (referer: https://www.lagou.com/zhaopin/Python/)
2017-05-01 00:06:16 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.lagou.com/jobs/2108656.html>
None
[Failure instance: Traceback: <class 'TypeError'>: connect() argument 3 must be str, not None
D:\Python35\lib\threading.py:914:_bootstrap_inner
D:\Python35\lib\threading.py:862:run
D:\Python35\lib\site-packages\twisted\_threads\_threadworker.py:46:work
D:\Python35\lib\site-packages\twisted\_threads\_team.py:190:doWork
--- <exception caught here> ---
D:\Python35\lib\site-packages\twisted\python\threadpool.py:250:inContext
D:\Python35\lib\site-packages\twisted\python\threadpool.py:266:<lambda>
D:\Python35\lib\site-packages\twisted\python\context.py:122:callWithContext
D:\Python35\lib\site-packages\twisted\python\context.py:85:callWithContext
D:\Python35\lib\site-packages\twisted\enterprise\adbapi.py:464:_runInteraction
D:\Python35\lib\site-packages\twisted\enterprise\adbapi.py:36:__init__
D:\Python35\lib\site-packages\twisted\enterprise\adbapi.py:76:reconnect
D:\Python35\lib\site-packages\twisted\enterprise\adbapi.py:431:connect
D:\Python35\lib\site-packages\MySQLdb\__init__.py:86:Connect
D:\Python35\lib\site-packages\MySQLdb\connections.py:204:__init__
]
 
给我你的怀抱
给我你的怀抱

全部回覆(1)
大家讲道理

從提示看出,你的配置(settings)的時候有1個參數是None,而不是字串

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板