When I use aiohttp.ClientSession resquest method to make a post request, it encounters CancelledErrors and I read the issue in https://github.com/aio-libs/aiohttp/issues/2056
I change the original code
async with self.session() as session:
async with session.request(
method,
url,
headers=headers,
params=self.combine_parameters(kwargs),
**kwargs
) as resp:
if resp.status >= 400:
raise ClientResponseError(
resp.status, resp.reason, await resp.content.read()
)
return await getattr(resp, return_method)()
async def my_asyn_job(session,method,url,headers,params,**kwargs):
async with session.request(
method,
url,
headers=headers,
params=params,
**kwargs
) as resp:
if resp.status >= 400:
raise ClientResponseError(
resp.status, resp.reason, await resp.content.read()
)
return await getattr(resp, return_method)()
async with self.session() as session:
job = await scheduler.spawn(my_asyn_job(session,method, url,headers=headers,params=self.combine_parameters(kwargs),**kwargs))
resp = await job.wait(timeout=300.0)
await scheduler.close()
return resp
However,I still encounter concurrent.futures._base.CancelledError(Read the log from bottom to top)
2019-12-28T18:46:45.692202891+08:00 concurrent.futures._base.CancelledError
2019-12-28T18:46:45.692196304+08:00 await self._waiter
2019-12-28T18:46:45.692193847+08:00 File "/usr/local/lib/python3.6/site-packages/aiohttp/streams.py", line 588, in read
2019-12-28T18:46:45.692191606+08:00 return self.gen.throw(type, value, traceback)
2019-12-28T18:46:45.692189024+08:00 File "/usr/local/lib/python3.6/asyncio/coroutines.py", line 129, in throw
2019-12-28T18:46:45.692186616+08:00 message, payload = await self._protocol.read() # type: ignore # noqa
2019-12-28T18:46:45.692183604+08:00 File "/usr/local/lib/python3.6/site-packages/aiohttp/client_reqrep.py", line 844, in start
2019-12-28T18:46:45.692181182+08:00 return self.gen.throw(type, value, traceback)
2019-12-28T18:46:45.692178663+08:00 File "/usr/local/lib/python3.6/asyncio/coroutines.py", line 129, in throw
2019-12-28T18:46:45.69217598+08:00 await resp.start(conn)
2019-12-28T18:46:45.692173366+08:00 File "/usr/local/lib/python3.6/site-packages/aiohttp/client.py", line 497, in _request
2019-12-28T18:46:45.692170814+08:00 return self.gen.throw(type, value, traceback)
2019-12-28T18:46:45.692163395+08:00 File "/usr/local/lib/python3.6/asyncio/coroutines.py", line 129, in throw
2019-12-28T18:46:45.692160872+08:00 self._resp = await self._coro
2019-12-28T18:46:45.692158225+08:00 File "/usr/local/lib/python3.6/site-packages/aiohttp/client.py", line 1005, in __aenter__
2019-12-28T18:46:45.692155291+08:00 return self.gen.throw(type, value, traceback)
2019-12-28T18:46:45.692151973+08:00 File "/usr/local/lib/python3.6/asyncio/coroutines.py", line 129, in throw
2019-12-28T18:46:45.69214951+08:00 **kwargs
2019-12-28T18:46:45.692146847+08:00 File "/data/code/rasa-1.2.9/rasa/utils/endpoints.py", line 144, in request
2019-12-28T18:46:45.692144459+08:00 return self.gen.throw(type, value, traceback)
2019-12-28T18:46:45.692141778+08:00 File "/usr/local/lib/python3.6/asyncio/coroutines.py", line 129, in throw
2019-12-28T18:46:45.692139103+08:00 json=json_body, method="post", timeout=DEFAULT_REQUEST_TIMEOUT
2019-12-28T18:46:45.692136388+08:00 File "/data/code/rasa-1.2.9/rasa/core/actions/action.py", line 399, in run
2019-12-28T18:46:45.692133807+08:00 return self.gen.throw(type, value, traceback)
2019-12-28T18:46:45.692129992+08:00 File "/usr/local/lib/python3.6/asyncio/coroutines.py", line 129, in throw
2019-12-28T18:46:45.692127126+08:00 events = await action.run(output_channel, nlg, tracker, self.domain)
2019-12-28T18:46:45.692124325+08:00 File "/data/code/rasa-1.2.9/rasa/core/processor.py", line 446, in _run_action
2019-12-28T18:46:45.692121434+08:00 Traceback (most recent call last):
I'm new to aiohttp and I can't quite understand the reason for this mistake。My two servers will interact with each other through a proxy server. Maybe the proxy server times out and then disconnects。I think my mistake is very similar to issue mentioned above.