zytedata/python-zyte-api

Getting request info from Exception Async

geg2102 opened this issue · 3 comments

When using the AsyncZyteAPI iter method, I want to know what url causes and error. Is there a way to extract this?

Could you try exception.request_info.url?

I think that may work, but even if it does, please just confirm it and keep this ticket open so that we update the docs, we should document attributes that RequestError inherits.

This gives the url of the endpoint https://api.zyte.com/v1/extract, not the url of the request.

Minimal example:

requests = [
    {"url": "https://linkedin.com", "httpResponseBody": True},
    {"url": "https://this.should.give.error", "httpResponseBody": True},
]
results = []
async with client.session() as session:
    for future in session.iter(requests):
        try:
            result = await future
        except RequestError as e:
            print(f"RequestError {e.request_info.url}")
        except Exception as e:
            print(f"NonRequestError")

result:

RequestError https://api.zyte.com/v1/extract
RequestError https://api.zyte.com/v1/extract

expected:

RequestError https://linkedin.com
RequestError https://this.should.give.error

In pyton-zyte-api 0.5.2 you can now use RequestError.query.