From 38af090f4d6799a0499b116a62c12509f59f561b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Chaves?= Date: Mon, 4 Feb 2019 11:17:58 +0100 Subject: [PATCH] Indicate that users must implement their own authentication result check The example of form-based login could lead some users to think its authentication result check was final. See https://stackoverflow.com/a/54410966/939364 This change should make it more obvious that users are expected to implement their own logic to check whether authentication worked or not. --- docs/topics/request-response.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/topics/request-response.rst b/docs/topics/request-response.rst index e29914dbf..76360b15f 100644 --- a/docs/topics/request-response.rst +++ b/docs/topics/request-response.rst @@ -489,6 +489,11 @@ method for this job. Here's an example spider which uses it:: import scrapy + def authentication_failed(response): + # TODO: Check the contents of the response and return True if it failed + # or False if it succeeded. + pass + class LoginSpider(scrapy.Spider): name = 'example.com' start_urls = ['http://www.example.com/users/login.php'] @@ -501,8 +506,7 @@ method for this job. Here's an example spider which uses it:: ) def after_login(self, response): - # check login succeed before going on - if "authentication failed" in response.body: + if authentication_failed(response): self.logger.error("Login failed") return