question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ItemLoader: support non-TextResponse

See original GitHub issue

At the moment, ItemLoader(response=response) fails if response is not a TextResponse instance.

Passing a binary response can still be useful, though. For example, to allow processors to access the response from their loader context, and hence be able to report the source URL (response.url) when reporting input issues.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Gallaeciocommented, Aug 16, 2021

@GeorgeA92 You are testing the upstream ItemLoader, Scrapy subclasses it to make some Scrapy-specific adjustments:

>>> from scrapy.http.response import Response
>>> from scrapy.loader import ItemLoader
>>> ItemLoader(response=Response(url='https://example.org'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/adrian/proxectos/scrapy/scrapy/loader/__init__.py", line 86, in __init__
    selector = self.default_selector_class(response)
  File "/home/adrian/proxectos/scrapy/scrapy/selector/unified.py", line 78, in __init__
    text = response.text
  File "/home/adrian/proxectos/scrapy/scrapy/http/response/__init__.py", line 129, in text
    raise AttributeError("Response content isn't text")
AttributeError: Response content isn't text

@calicomills That avoids the exception, but prevents the response from being available from a loader context, so it does not really solve the root issue.

1reaction
Gallaeciocommented, Jul 16, 2021

Thar’s great! No need to ask for permission 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

Item Loaders — Scrapy 2.7.1 documentation
Item Loaders are an extension of the itemloaders library that make it easier to work with Scrapy by adding support for responses.
Read more >
Item Loader not working with response.meta - Stack Overflow
I want to load two items into an item loader, that is instantiated through the response.meta command. Somehow, the standard:
Read more >
Demystifying Scrapy Item Loaders - Towards Data Science
In this article, we will define what an item loader is in comparison to Items. ... This is how ItemLoaders gets the data...
Read more >
Item Loaders in Scrapy - YouTube
Item loaders can help you keep the spiders clean. Item loaders use input processors and output processors to clean up and process each...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found