Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: Response content isn't text in "response_is_ban" #58

Open
iamumairayub opened this issue Mar 1, 2021 · 1 comment
Open

Comments

@iamumairayub
Copy link

I have created this policy

class MyBanPolicy(BanDetectionPolicy):
    def response_is_ban(self, request, response):
        # use default rules, but also consider HTTP 200 responses
        ban = super(MyBanPolicy, self).response_is_ban(request, response)

        if b'tests' in response.body:
            logging.info('test found')
            ban = True

        return ban

But my check doesnt work because response is I think gzipped

I tried response.css("my selector").get() but I get AttributeError: Response content isn't text error

How can I check existence of an element using response.css() in response_is_ban method?

Do I need to first unzip the response each time? that does not look suitable

PS: I am not sending gzip deflate header to target website at all

Python 3.6.9
Scrapy 2.3.0

@fschn90
Copy link

fschn90 commented Jun 7, 2023

have you found a solution or workaround for this?

im trying something similar:

class BanPolicy(BanDetectionPolicy):
    def response_is_ban(self, request, response):
        port = response.meta.get('proxy')[-4:]

but am also getting an error:

return self.request.meta
AttributeError: 'NoneType' object has no attribute 'meta'

AttributeError: Response.meta not available, this response is not tied to any request

thanks in advance!
Best, Flo

Python 3.10.6
Scrapy 2.8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants