Skip to content

ClientPayloadError #9

@gimler

Description

@gimler
  • Python version: 3.6.3
  • Operating System: Ubuntu 1604
  • aiohttp version:
    aiohttp (3.6.1)
    aiohttp-sse-client (0.1.6)

Description

sometime i get ClientPayloadError

Task exception was never retrieved
future: <Task finished coro=<main() done, defined at prog.python:39> exception=NameError("name 'ClientPayloadError' is not defined",)>
Traceback (most recent call last):
  File "prog.python", line 23, in get_stock
    async for event in event_source:
  File "/home/?/.local/lib/python3.6/site-packages/aiohttp_sse_client/client.py", line 146, in __anext__
    async for line_in_bytes in self._response.content:
  File "/home/?/.local/lib/python3.6/site-packages/aiohttp/streams.py", line 39, in __anext__
    rv = await self.read_func()
  File "/home/?/.local/lib/python3.6/site-packages/aiohttp/streams.py", line 328, in readline
    await self._wait('readline')
  File "/home/?/.local/lib/python3.6/site-packages/aiohttp/streams.py", line 296, in _wait
    await waiter
aiohttp.client_exceptions.ClientPayloadError: Response payload is not completed

What I Did

from aiohttp import ClientSession, ClientTimeout, ClientPayloadError
from aiohttp_sse_client import client as sse_client
...
timeout = ClientTimeout(sock_read=0)
    session = ClientSession(timeout=timeout)

    async with sse_client.EventSource(url, session=session) as event_source:
        try:
            async for event in event_source:
                j = json.loads(event.data)
                if 'value' in j:
#                    print(json.dumps(j, indent=4, sort_keys=True))
                    print(label + " " + str(j["value"]))
        except ConnectionError:
            pass
        except ClientPayloadError:
            pass

is there a better way to handle this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions