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)