scrapy-zyte-api icon indicating copy to clipboard operation
scrapy-zyte-api copied to clipboard

DummyResponse

Open bulatbulat48 opened this issue 1 year ago • 5 comments

When we add a type hint DummyResponse to the response as it mentioned here:

The scrapy doesn't send the actions, experimental, cookies or other additional settings added to the settings or the the request:

Maybe it's a cloudflare related issue, idk.

cookies = {
    'bh_cookies_accepted': True,
    'bh_cookies_allow_all': True,
    'bh_cookies_allow_marketing': True,
    'bh_cookies_allow_statistic': True,
    'bh_cookies_allow_thirdcountries': True,
},
@classmethod
def update_settings(cls, settings: BaseSettings) -> None:
    settings["ZYTE_API_EXPERIMENTAL_COOKIES_ENABLED"] = True
    settings["ZYTE_API_LOG_REQUESTS"] = True
    settings["ZYTE_API_LOG_REQUESTS_TRUNCATE"] = 1000
    return super().update_settings(settings)
2024-09-26 20:40:50 [scrapy_poet.downloadermiddlewares] DEBUG: Using DummyResponse instead of downloading <GET https://www.example.com/>
2024-09-26 20:40:50 [scrapy_zyte_api.handler] DEBUG: Sending Zyte API extract request: {"browserHtml": true, "url": "https://www.example.com"}

bulatbulat48 avatar Oct 14 '24 13:10 bulatbulat48

@bulatbulat48 could you please also provide the example of the callback you're using? The signature is enough.

kmike avatar Oct 15 '24 10:10 kmike

@kmike sure:

async def parse_product(
        self, response: DummyResponse, product_dpo: ProductPageObject
):

bulatbulat48 avatar Oct 15 '24 10:10 bulatbulat48

What are the dependencies of ProductPageObject?

kmike avatar Oct 15 '24 10:10 kmike

@kmike

from web_poet import BrowserResponse, HttpResponse, ItemPage, PageParams, field

@attrs.define(auto_attribs=True)
class ProductPageObject(ItemPage[ProductItem]):
    response: BrowserResponse
    page_params: PageParams

bulatbulat48 avatar Oct 15 '24 10:10 bulatbulat48

The behavior here is as designed, Zyte API params for provider dependencies can only be altered with the zyte_api_provider request metadata key or the ZYTE_API_PROVIDER_PARAMS setting.

However, I wonder if for some parameters, like cookies, we should make things behave like automap, or at least make it easier for them to do that, instead of requiring those cookies to be specified in those settings as Zyte API params.

Gallaecio avatar Oct 16 '24 08:10 Gallaecio