-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Provide a way to associate context with requests #836
Comments
Hi, I think it's pretty trivial as you can simply replace async def foo(session):
async def get(original_url):
resp = await session.get(original_url)
return original_url, resp
urls = {'http://site.example/{}'.format(i): {'data': i} for i in range(3)}
for resp_f in asyncio.as_completed([get(url) for url in urls.keys()]):
try:
original_url, resp = await resp_f
async with resp:
data = await resp.read()
except ...
# .... which is more flexible |
Agree with @popravich |
If the request fails then |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Long story short
I'm trying to fetch from a number of URLs. If the requests succeed, I'm using the request URL as a key to look up contextual data about the request, to be used along with the fetched data. But if the response is a redirect, I have to handle looking into the history to determine the original URL. This is possible but inconvenient.
If the requests fail, I can catch the exception but I've no way to access the original request, so I can't look up the data.
Expected behaviour
I'm not sure what I want the solution to look like, but I'd like some way of associating contextual data with a request so that it can be retrieved once the request is complete, regardless of whether it succeeded or failed.
Steps to reproduce
Your environment
python 3.5.1+ on Debian stretch
aiohttp 0.21.4
The text was updated successfully, but these errors were encountered: