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

Passing proxy via meta in start request throws KeyError: 'exception' #54

Open
superryeti opened this issue Jun 14, 2019 · 1 comment
Open

Comments

@superryeti
Copy link

superryeti commented Jun 14, 2019

I see this is caused by the line no 83.

 if 'proxy' in request.meta:
            if request.meta["exception"] is False:
                return

If we have used proxy in start requests function then this issue arises which makes sense because exception is not defined in meta up to this point for our first request.

I guess most of us either use a random proxy or custom proxy. So no one ever bothered about it.
I think the line 83 is important because it enables to change proxies in each retry or after exception.

def start_requests(self):

        yield scrapy.Request('http://quotes.toscrape.com/', callback=self.parse, meta={'proxy': 'http://xxxx:xxxx@xxxx:xxxx'})

Also to change the proxy in retry. Comment out this in process_exception. #15

       if 'proxy' not in request.meta:
             return
@superryeti
Copy link
Author

This solves the issue. Now we can pass the proxy in our first request via meta. and our script would still handle retries with new proxies

if 'proxy' in request.meta:
            if request.meta.get("exception", True):
                log.info('Using custom proxy provided in meta')
                    return

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

1 participant