You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用aiohttp批量发送POST请求时程序挂起并抛出ClientOSError的问题求助

使用aiohttp批量发送POST请求时程序挂起并抛出ClientOSError的问题求助

我现在在用aiohttp批量发送POST请求,但遇到了一个棘手的问题——程序永远没法推进到第一个请求之后的操作,会挂起好一会儿,然后抛出下面的错误。

我的posted函数代码如下:

import aiohttp
from urllib import parse
# 假设get_random_user_agent是已实现的函数

async def posted(URL, payload):
    
    #'Content-Type': 'application/json'}
    headers = {'User-Agent': get_random_user_agent(),
              'ngrok-skip-browser-warning': '100'}
              
    async with aiohttp.ClientSession(URL, headers=headers) as session:
        for i, data in enumerate(payload):
          if data[0] is not None and data[1] is not None:
            print(data[1], len(data[0]))
            myobj = {'url_input': data[1], 'text_input': data[0]}
            encoded_data = parse.urlencode(myobj).encode()
            async with session.post('/', json=myobj):
                print('posted')
        #await session.close()

调用方式是:

await posted(URL, work_list)

其中work_list的定义为:

work_list = [('content', 'url'),('content1', 'url1')]

抛出的错误信息如下:

The above exception was the direct cause of the following exception:

ClientOSError                             Traceback (most recent call last)

/usr/local/lib/python3.11/dist-packages/aiohttp/streams.py in read(self)
    669             self._waiter = self._loop.create_future()
    670             try:
--> 671                 await self._waiter
    672             except (asyncio.CancelledError, asyncio.TimeoutError):
    673                 self._waiter = None

ClientOSError: [Errno 1] [SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:2580)

我之前猜测这可能是因为ngrok用HTTPS转发到HTTP服务导致的,所以特意在Flask应用里配置了临时SSL证书,重启了ngrok,但现在调试日志里完全看不到请求过来,还是遇到类似的问题。

备注:内容来源于stack exchange,提问作者disruptive

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 15:13:09