当我尝试在 Quart 端点中使用 aiohttp 进行获取或发布调用时,它会抛出“现有连接被远程主机强行关闭”,即使我按照官方教程here
我注意到我不是唯一报告此问题的人,我认为是 aiohhtp 和 Quart 之间的某种交互中断了。
异步GET方法:
async def _call_api_get(self, url : str, json_data : dict = None) -> ApiResponse:
try:
async with aiohttp.ClientSession() as session:
async with session.get(url, json=json_data) as resp:
body = await resp.json() \
if resp.content_type == 'application/json' \
else await resp.text()
api_return = ApiResponse(
status_code = resp.status,
body = body,
content_type = resp.content_type)
except ConnectionResetError as ex:
print("ConnectionResetError:", ex)
except Exception as ex:
api_return = ApiResponse(exception_msg = ex)
return api_return
API端点方法:
async def my_endpoint(self) -> Response:
auth_url = 'http://www.google.co.uk'
api_return_body : dict = {"key": "value"}
api_response = await self._call_api_get(auth_url,
json_data=auth_request)
我看的其他相关问题: