scrapy/docs/topics/exceptions.rst

1.5 KiB

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> </head>

Exceptions

Built-in Exceptions reference

System Message: ERROR/3 (<stdin>, line 7)

Unknown directive type "module".

.. module:: scrapy.exceptions
   :synopsis: Scrapy exceptions

Here's a list of all exceptions included in Scrapy and their usage.

DropItem

System Message: ERROR/3 (<stdin>, line 20)

Unknown directive type "exception".

.. exception:: DropItem

The exception that must be raised by item pipeline stages to stop processing an Item. For more information see :ref:`topics-item-pipeline`.

System Message: ERROR/3 (<stdin>, line 22); backlink

Unknown interpreted text role "ref".

CloseSpider

System Message: ERROR/3 (<stdin>, line 28)

Unknown directive type "exception".

.. exception:: CloseSpider(reason='cancelled')

    This exception can be raised from a spider callback to request the spider to be
    closed/stopped. Supported arguments:

    :param reason: the reason for closing
    :type reason: str

For example:

def parse_page(self, response):
    if 'Bandwidth exceeded' in response.body:
        raise CloseSpider('bandwidth_exceeded')

IgnoreRequest

System Message: ERROR/3 (<stdin>, line 45)

Unknown directive type "exception".

.. exception:: IgnoreRequest

This exception can be raised by the Scheduler or any downloader middleware to indicate that the request should be ignored.

NotConfigured

System Message: ERROR/3 (<stdin>, line 53)

Unknown directive type "exception".

.. exception:: NotConfigured

This exception can be raised by some components to indicate that they will remain disabled. Those components include:

  • Extensions
  • Item pipelines
  • Downloader middlewares
  • Spider middlewares

The exception must be raised in the component's __init__ method.

NotSupported

System Message: ERROR/3 (<stdin>, line 68)

Unknown directive type "exception".

.. exception:: NotSupported

This exception is raised to indicate an unsupported feature.

</html>