1
0
mirror of https://github.com/scrapy/scrapy.git synced 2025-02-24 12:03:47 +00:00

added FAQ about error: "cannot import name crawler"

This commit is contained in:
Pablo Hoffman 2013-03-14 12:56:30 -03:00
parent a862f23376
commit 098ccff862

View File

@ -273,6 +273,38 @@ I'm scraping a XML document and my XPath selector doesn't return any items
You may need to remove namespaces. See :ref:`removing-namespaces`.
I'm getting an error: "cannot import name crawler"
--------------------------------------------------
This is caused by Scrapy changes due to the singletons removal. The error is
most likely raised by a module (extension, middleware, pipeline or spider) in
your Scrapy project that imports ``crawler`` from ``scrapy.project``. For
example::
from scrapy.project import crawler
class SomeExtension(object):
def __init__(self):
self.crawler = crawler
# ...
This way to access the crawler object is deprecated, the code should be ported
to use ``from_crawler`` class method, for example::
class SomeExtension(object):
@classmethod
def from_crawler(cls, crawler):
o = cls()
o.crawler = crawler
return o
Scrapy command line tool has some backwards compatibility in place to still
support the old import mechanism (with a deprecation warning), but this
mechanism may not work if you use Scrapy differently (for example, as a
library).
.. _user agents: http://en.wikipedia.org/wiki/User_agent
.. _LIFO: http://en.wikipedia.org/wiki/LIFO
.. _DFO order: http://en.wikipedia.org/wiki/Depth-first_search