1
0
mirror of https://github.com/scrapy/scrapy.git synced 2025-02-21 06:33:07 +00:00

FilesPipeline.file_path has optional arguments

Documented signature doesn't match the actual interface in [files.py](https://github.com/scrapy/scrapy/blob/master/scrapy/pipelines/files.py#L520).

Specifically, it looks like it may be [called](https://github.com/scrapy/scrapy/blob/master/scrapy/pipelines/files.py#L422) without a response value.

I found this when I was implementing the pipeline with the signature `file_path(self, request, response, info)` and the following error was being return in my results :

    [(False, <twisted.python.failure.Failure builtins.TypeError: file_path() missing 1 required positional argument: 'response'>)]

Scrapy==1.8.0
This commit is contained in:
Daniel Kimsey 2020-01-26 13:21:31 -06:00 committed by Daniel Kimsey
parent a3b168948c
commit 752e8f7018

View File

@ -410,7 +410,7 @@ See here the methods that you can override in your custom Files Pipeline:
.. class:: FilesPipeline .. class:: FilesPipeline
.. method:: file_path(request, response, info) .. method:: file_path(self, request, response=None, info=None)
This method is called once per downloaded item. It returns the This method is called once per downloaded item. It returns the
download path of the file originating from the specified download path of the file originating from the specified
@ -434,7 +434,7 @@ See here the methods that you can override in your custom Files Pipeline:
class MyFilesPipeline(FilesPipeline): class MyFilesPipeline(FilesPipeline):
def file_path(self, request, response, info): def file_path(self, request, response=None, info=None):
return 'files/' + os.path.basename(urlparse(request.url).path) return 'files/' + os.path.basename(urlparse(request.url).path)
By default the :meth:`file_path` method returns By default the :meth:`file_path` method returns
@ -524,7 +524,7 @@ See here the methods that you can override in your custom Images Pipeline:
The :class:`ImagesPipeline` is an extension of the :class:`FilesPipeline`, The :class:`ImagesPipeline` is an extension of the :class:`FilesPipeline`,
customizing the field names and adding custom behavior for images. customizing the field names and adding custom behavior for images.
.. method:: file_path(request, response, info) .. method:: file_path(self, request, response=None, info=None)
This method is called once per downloaded item. It returns the This method is called once per downloaded item. It returns the
download path of the file originating from the specified download path of the file originating from the specified
@ -548,7 +548,7 @@ See here the methods that you can override in your custom Images Pipeline:
class MyImagesPipeline(ImagesPipeline): class MyImagesPipeline(ImagesPipeline):
def file_path(self, request, response, info): def file_path(self, request, response=None, info=None):
return 'files/' + os.path.basename(urlparse(request.url).path) return 'files/' + os.path.basename(urlparse(request.url).path)
By default the :meth:`file_path` method returns By default the :meth:`file_path` method returns