问答详情
源自:2-8 保存数据

插入数据self.post.insert(data)时报错pymongo.errors.ServerSelectionTimeoutError

2019-02-16 11:39:59 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://movie.douban.com/robots.txt> (referer: None)

2019-02-16 11:40:00 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://movie.douban.com/top250> (referer: None)

2019-02-16 11:40:30 [scrapy.core.scraper] ERROR: Error processing {'description': '希望让人自由。',

 'evaluate_number': '1318433人评价',

 'introduction': '1994/美国/犯罪剧情',

 'movie_name': '肖申克的救赎',

 'serial_number': '1',

 'star_level': '9.6'}

Traceback (most recent call last):

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/twisted/internet/defer.py", line 654, in _runCallbacks

    current.result = callback(current.result, *args, **kw)

  File "/Users/sky/work/practice/pycharm/douban/douban/douban/pipelines.py", line 25, in process_item

    self.post.insert(data)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/collection.py", line 3161, in insert

    check_keys, manipulate, write_concern)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/collection.py", line 607, in _insert

    bypass_doc_val, session)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/collection.py", line 595, in _insert_one

    acknowledged, _insert_command, session)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1247, in _retryable_write

    with self._tmp_session(session) as s:

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 112, in __enter__

    return next(self.gen)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1576, in _tmp_session

    s = self._ensure_session(session)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1563, in _ensure_session

    return self.__start_session(True, causal_consistency=False)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1516, in __start_session

    server_session = self._get_server_session()

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1549, in _get_server_session

    return self._topology.get_server_session()

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/topology.py", line 427, in get_server_session

    None)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/topology.py", line 199, in _select_servers_loop

    self._error_message(selector))

pymongo.errors.ServerSelectionTimeoutError: 218.98.27.210:27017: timed out

2019-02-16 11:41:00 [scrapy.core.scraper] ERROR: Error processing {'description': '风华绝代。',

 'evaluate_number': '973528人评价',

 'introduction': '1993/中国大陆香港/剧情爱情同性',

 'movie_name': '霸王别姬',

 'serial_number': '2',

 'star_level': '9.6'}

Traceback (most recent call last):

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/twisted/internet/defer.py", line 654, in _runCallbacks

    current.result = callback(current.result, *args, **kw)

  File "/Users/sky/work/practice/pycharm/douban/douban/douban/pipelines.py", line 25, in process_item

    self.post.insert(data)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/collection.py", line 3161, in insert

    check_keys, manipulate, write_concern)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/collection.py", line 607, in _insert

    bypass_doc_val, session)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/collection.py", line 595, in _insert_one

    acknowledged, _insert_command, session)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1247, in _retryable_write

    with self._tmp_session(session) as s:

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 112, in __enter__

    return next(self.gen)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1576, in _tmp_session

    s = self._ensure_session(session)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1563, in _ensure_session

    return self.__start_session(True, causal_consistency=False)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1516, in __start_session

    server_session = self._get_server_session()

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1549, in _get_server_session

    return self._topology.get_server_session()

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/topology.py", line 427, in get_server_session

    None)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymongo/topology.py", line 199, in _select_servers_loop

    self._error_message(selector))

pymongo.errors.ServerSelectionTimeoutError: 218.98.27.210:27017: timed out

2019-02-16 11:41:00 [scrapy.extensions.logstats] INFO: Crawled 2 pages (at 2 pages/min), scraped 0 items (at 0 items/min)


提问者:慕仰3868320 2019-02-16 11:58

个回答

  • 十指狂魔
    2019-02-16 23:12:12

    mongodb连接超时,试试看你MongoDB数据库在你本地是否能访问得到吧?