From d9b4850c446f028131b0c2d78266f5ad48306b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Tue, 11 Aug 2015 14:09:49 -0300 Subject: [PATCH] explicit close file on file:// scheme handler --- scrapy/core/downloader/handlers/file.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scrapy/core/downloader/handlers/file.py b/scrapy/core/downloader/handlers/file.py index 5a63e9d08..9346ce08d 100644 --- a/scrapy/core/downloader/handlers/file.py +++ b/scrapy/core/downloader/handlers/file.py @@ -10,6 +10,7 @@ class FileDownloadHandler(object): @defers def download_request(self, request, spider): filepath = file_uri_to_path(request.url) - body = open(filepath, 'rb').read() + with open(filepath, 'rb') as fo: + body = fo.read() respcls = responsetypes.from_args(filename=filepath, body=body) return respcls(url=request.url, body=body)