Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.2k views
in Technique[技术] by (71.8m points)

python - What key differences are there between aiohttp.ClientSession and requests.session?

I'm experimenting with these two different libraries to submit a series of POST requests to routes on the same domain (i.e. domain/routeA, domain/routeB, domain/routeC, etc.). The problem is that when I use aiohttp.ClientSession, it seems to fetch the response from the first POST request but then receive incomplete response after that. However, when I use requests.session, I get all the responses properly. I'm not sure if there's any particular difference in these session types that's causing this or whatnot. I've verified that I'm passing the proper payload (I pass it as data=payload for both, so I think that the issue is not something that has to do with like having to set type to json / files / etc. There are no headers passed for both cases. The following is how I'm setting up each session

import aiohttp

tcp_connector = aiohttp.TCPConnector(limit=None, limit_per_host=0, ssl=False)
session = aiohttp.ClientSession(connector=tcp_connector)

resp = await session.post(...) # in async event loop, not sure if the event loop has an effect
import requests

session = requests.session

session.post(...)

If anyone knows what could be causing the issue, I'd really appreciate some help here. Thanks in advance!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...