-
Notifications
You must be signed in to change notification settings - Fork 20
Description
Hi, I am testing aiohttp-sse-client to get SSE message from https server to raspberry pi client.
tested source is as follows:
import asyncio
from datetime import timedelta
from aiohttp_sse_client import client as sse_client
import logging
logging.basicConfig(filename="log_sse_test.txt", level=logging.DEBUG)
RECONNECTION_TIME = timedelta(seconds=3)
id = "aaaa"
token = "abcd"
async def main():
async with sse_client.EventSource(f'https://server/subscribe?id={id}', reconnection_time = RECONNECTION_TIME, headers = {'TOKEN': token}) as event_source:
try:
async for event in event_source:
logging.debug(f"msg={event}")
print(f"msg={event}")
logging.debug(f"type={event.type},message={event.message},data={event.data}")
except ConnectionError:
pass
except Exception as e:
logging.debug(f"error={e}")
print(f"error={e}")
asyncio.run(main())After running this programm, I got first message successfully.
But next time after reconnection time, I got error message 'Response payload is not completed' and program exits.
msg=MessageEvent(...)
error=Response payload is not completed(... is type="aa", message="bb", data='{"a": "b"}', origin="server", last_event_id="cc")
I found work-around to work with continous reconnection.
I added try-except to 'async for' blocks of aiohttp-sse-client/client.py
https://github.com/rtfol/aiohttp-sse-client/blob/e311075ac8b9b75d8b09512f8638f1dd03e2ef2b/aiohttp_sse_client/client.py#L157C13-L157C18
while self._response.status != 204:
try:
async for line_in_bytes in self._response.content:
# ...
except ClientPayloadError as e:
print(f"ERROR:__anext__:{e}")And my program works with continous reconnection after printing event message and error
msg=MessageEvent(...)
ERROR:__anext__:Response payload is not completed
msg=MessageEvent(...)
ERROR:__anext__:Response payload is not completedIs this bug of library?
Or is this work-around bad?
Why 'Response payload is not completed' error occurs?
Please help me.