diff --git a/scrapy/trunk/docs/ref/request-response.rst b/scrapy/trunk/docs/ref/request-response.rst index b514f1d22..d524d0a3b 100644 --- a/scrapy/trunk/docs/ref/request-response.rst +++ b/scrapy/trunk/docs/ref/request-response.rst @@ -25,61 +25,73 @@ below in :ref:`ref-request-subclasses` and :ref:`ref-response-subclasses`. Request objects =============== -.. class:: Request(url[, callback, method, body, headers, cookies, meta, encoding, dont_filter, errback]) +.. class:: Request(url[, callback, method='GET', body, headers, cookies, meta, encoding='utf-8', dont_filter=False, errback]) A :class:`Request` object represents an HTTP request, which is usually generated in the Spider and executed by the Downloader, and thus generating a :class:`Response`. - ``url`` is a string containing the URL for this request + :param url: the URL of this request + :type url: string - ``callback`` is a function that will be called with the response of this - request (once its downloaded) as its first parameter. For more information - see :ref:`ref-request-callback-arguments` below. + :param callback: the function that will be called with the response of this + request (once its downloaded) as its first parameter. For more information + see :ref:`ref-request-callback-arguments` below. + :type callback: callable - ``method`` is a string with the HTTP method of this request, and defaults - to ``'GET'``. + :param method: the HTTP method of this request. Defaults to ``'GET'``. + :type method: string - ``meta`` is a dict containing the initial values for the - :attr:`Request.meta` attribute. If passed, the dict will be shallow copied. + :param meta: the initial values for the :attr:`Request.meta` attribute. If + given, the dict passed in this parameter will be shallow copied. + :type meta: dict - ``body`` is a str or unicode containing the request body. - If ``body`` is a `unicode` it's encoded to str using the `encoding` passed. - If ``body`` is None, an empty string is stored. - In any case, the final stored value will be a string (never unicode, never None). + :param body: the request body. If a ``unicode`` is passed, then it's encoded to + ``str`` using the `encoding` passed (which defaults to ``utf-8``). If + ``body`` is not given,, an empty string is stored. Regardless of the + type of this argument, the final value stored will be a ``str``` (never + ``unicode`` or ``None``). + :type body: str or unicode - ``headers`` is a multi-valued dict containing the headers of this request + :param headers: the headers of this request. The dict values can be strings + (for single valued headers) or lists (for multi-valued headers). + :type headers: dict - ``cookies`` is a dict containing the request cookies. Example:: + :param cookies: the request cookies. Example:: - request_with_cookies = Request(url="http://www.example.com", - cookies={currency: 'USD', country: 'UY'}) + request_with_cookies = Request(url="http://www.example.com", + cookies={currency: 'USD', country: 'UY'}) - When some site returns cookies (in a response) those are stored in the - cookies for that domain and will be sent again in future Requests. That's - the typical behaviour of any regular web browser. However, if, for some - reason, you want to avoid merging with existing cookies you can instruct - Scrapy to do so by setting the ``dont_merge_cookies`` item in the - Request.meta. - - Example of request without merging cookies:: + When some site returns cookies (in a response) those are stored in the + cookies for that domain and will be sent again in future requests. That's + the typical behaviour of any regular web browser. However, if, for some + reason, you want to avoid merging with existing cookies you can instruct + Scrapy to do so by setting the ``dont_merge_cookies`` item in the + :attr:`Request.meta`. + + Example of request without merging cookies:: - request_with_cookies = Request(url="http://www.example.com", - cookies={currency: 'USD', country: 'UY'}, - meta={'dont_merge_cookies': True}) + request_with_cookies = Request(url="http://www.example.com", + cookies={currency: 'USD', country: 'UY'}, + meta={'dont_merge_cookies': True}) + :type cookies: dict - ``encoding`` is a string with the encoding of this request (defaults to - ``'utf-8'``). This encoding will be used to percent-encode the URL and to - convert the body to str (when given as unicode). + :param encoding: the encoding of this request (defaults to ``'utf-8'``). + This encoding will be used to percent-encode the URL and to convert the + body to ``str`` (if given as ``unicode``). + :type encoding: string - ``dont_filter`` is a boolean which indicates that this request should not - be filtered by the scheduler. This is used when you want to perform an - identical request multiple times, for whatever reason + :param dont_filter: indicates that this request should not be filtered by + the scheduler. This is used when you want to perform an identical + request multiple times, to ignore the duplicates filter. Use it with + care, or you will get into crawling loops. Default to ``False``. + :type dont_filter: boolean - ``errback`` is a function that will be called if any exception was raised - while processing the request in Scrapy. This includes pages that failed - with 404 HTTP errors and such. , it receives a `Twisted Failure`_ - instance as first parameter. + :param errback: a function that will be called if any exception was + raised while processing the request. This includes pages that failed + with 404 HTTP errors and such. It receives a `Twisted Failure`_ instance + as first parameter. + :type errback: callable .. _Twisted Failure: http://twistedmatrix.com/documents/8.2.0/api/twisted.python.failure.Failure.html @@ -240,27 +252,36 @@ objects. remaining arguments are the same as for the :class:`Request` class and are not documented here. - ``formdata`` is a dictionary (or iterable of (key, value) tuples) containing - HTML Form data which will be url-encoded and assigned to the body of the - request. + :param formdata: is a dictionary (or iterable of (key, value) tuples) + containing HTML Form data which will be url-encoded and assigned to the + body of the request. + :type formdata: dict or iterable of tuples The :class:`FormRequest` objects support the following class method in addition to the standard :class:`Request` methods: - .. classmethod:: FormRequest.from_response(response, [formnumber, formdata, ...]) + .. classmethod:: FormRequest.from_response(response, [formnumber=0, formdata, ...]) - Returns a new :class:`FormRequest` object with its form field values - pre-populated with those found in the HTML ``