1
0
mirror of https://github.com/scrapy/scrapy.git synced 2025-03-15 10:51:48 +00:00

Update docs on accessing callback arguments in errback (#4634)

This commit is contained in:
Devi Sandeep 2020-06-18 05:01:38 -05:00 committed by GitHub
parent 3d027fb578
commit 5d54173187
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -189,6 +189,10 @@ Request objects
cloned using the ``copy()`` or ``replace()`` methods, and can also be
accessed, in your spider, from the ``response.cb_kwargs`` attribute.
In case of a failure to process the request, this dict can be accessed as
``failure.request.cb_kwargs`` in the request's errback. For more information,
see :ref:`topics-request-response-ref-accessing-callback-arguments-in-errback`.
.. method:: Request.copy()
Return a new Request which is a copy of this Request. See also:
@ -312,6 +316,31 @@ errors if needed::
request = failure.request
self.logger.error('TimeoutError on %s', request.url)
.. _topics-request-response-ref-accessing-callback-arguments-in-errback:
Accessing additional data in errback functions
----------------------------------------------
In case of a failure to process the request, you may be interested in
accessing arguments to the callback functions so you can process further
based on the arguments in the errback. The following example shows how to
achieve this by using ``Failure.request.cb_kwargs``::
def parse(self, response):
request = scrapy.Request('http://www.example.com/index.html',
callback=self.parse_page2,
errback=self.errback_page2,
cb_kwargs=dict(main_url=response.url))
yield request
def parse_page2(self, response, main_url):
pass
def errback_page2(self, failure):
yield dict(
main_url=failure.request.cb_kwargs['main_url'],
)
.. _topics-request-meta:
Request.meta special keys