小编Nia*_*ing的帖子

Python aiohttp请求已停止,但没有异常

aiohttp用来请求网址.大部分时间它正常运行,但有时它会停止而不会引发任何异常.

正如您在代码中看到的,我捕获了所有异常,但是当它停止时,不会打印异常日志.

日志看起来像:

get_live_league_games: while True
try
yield from aiohttp.request
Run Code Online (Sandbox Code Playgroud)

但' res = yield from r.json()'不打印,它停止并且不会抛出任何异常.

while True:
    print('get_live_league_games: while True')
    start = time.clock()
    try:
        print('try')
        r = yield from aiohttp.request('GET',url)
        print('yield from aiohttp.request')
        res = yield from r.json()
        print('res = yield from r.json()')
    except aiohttp.errors.DisconnectedError as e:
        logging.warning('get_live_league_games:',e)
        yield from asyncio.sleep(10)
        continue
    except aiohttp.errors.ClientError as e:
        logging.warning('get_live_league_games:',e)
        yield from asyncio.sleep(10)
        continue
    except aiohttp.errors.HttpProcessingError as e:
         logging.warning('get_live_league_games:',e)
         yield from asyncio.sleep(10)
         continue
    except Exception as e:
         logging.warning('get_live_league_games,Exception:',e)
         yield …
Run Code Online (Sandbox Code Playgroud)

python python-3.x python-asyncio aiohttp

6
推荐指数
1
解决办法
1269
查看次数

标签 统计

aiohttp ×1

python ×1

python-3.x ×1

python-asyncio ×1