Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Too big events #25

Open
Michdo93 opened this issue Sep 16, 2022 · 1 comment
Open

Too big events #25

Michdo93 opened this issue Sep 16, 2022 · 1 comment

Comments

@Michdo93
Copy link

Hi,

I use SSE to query the events of items from openHAB. I can do this there via the REST API. However, I have a problem with images. If I change a large image and replace it with a small one, the SSE events do not break.

However, if I replace a small image with a large one, it fails tremendously.

Here the part of my code:

import json
import pprint
import sseclient

if __name__ == "__main__":
    events = sseclient.SSEClient("http://192.168.0.5:8080/rest/events?topics=openhab/items/testImage/state")

    for event in events:
        print(event)
        print(type(event))
        print(type(event.data))
        print(len(event.data))
        pprint.pprint(event)

        try:
            if len(event.data) > 0:
                data = json.loads(event.data)

                event_topic = data.get("topic")
                event_item_name = event_topic.split("/")[2]
                event_payload = eval(data.get("payload"))
                event_type = data.get("type")

                print(event_item_name)
        except json.decoder.JSONDecodeError:
            print("Event could not be converted from JSON")

I check it in return with Curl, of course. There I see that a big event is arriving.

If I run my Python script, I get:

{"topic":"openhab/items/testImage/state","payload":"{\"type\":\"Raw\",\"value\":\"data:image/jpg;base64,R0lGODlhAQABAIAAAP7//wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw\\u003d\\u003d\"}","type":"ItemStateEvent"}
<class 'sseclient.Event'>
<class 'str'>
205
<sseclient.Event object at 0x7f435da7ffa0>
testImage

<class 'sseclient.Event'>
<class 'str'>
0
<sseclient.Event object at 0x7f435da7ff70>

<class 'sseclient.Event'>
<class 'str'>
0
<sseclient.Event object at 0x7f435da7ffa0>

<class 'sseclient.Event'>
<class 'str'>
0
...

Or in other words: Instead of receiving anything big, I suddenly receive nothing at all. The loop makes another iteration. That's all well and good. But for some reason this event is then empty. My assumption would be that it would be too large to be processed.

This is the equvialent command with curl:

curl "http://192.168.0.5:8080/rest/events?topics=openhab/items/testImage/state"

I receive:

...
event: message
data: {"topic":"openhab/items/testImage/state","payload":"{\"type\":\"Raw\",\"value\":\"data:image/jpg;base64,
....

It would be definitely too long to post the whole answer because an image is very long.

@mpetazzoni
Copy link
Owner

I've definitely never validated this library on large events when all the data is on a single line.

Can you try enabling debug logging on the library's logger? I'm trying to see if it's hitting the check from https://github.com/mpetazzoni/sseclient/blob/master/sseclient/__init__.py#L75

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants