Rest API Subscription

Hello CodeShepherd 


Hello all we have been trying to get the complex subscription working, following the guide. but
im able to create the complex subscribe node where i get the code 201 but if i then try to execute a get like the examplei get nothing back. Thanks for you help
With kind regards,
David Maenen

 

 

with kinde regards,
David

Best reply by Sgilk

david4 ,

Like CodeShepherd said, you need a client that supports SSE. Python requests does not. See sseclient-py as an example.

Here is a modification of your code above.

    # Make the POST request
    motion_info = requests.post(url, json=payload, headers=head, verify=False)

    # Check the response for the POST request
    if motion_info.status_code == 201:

        response_data = motion_info.json  # Call the method to get JSON data

        print(response_data)  # Print the response data

    else:
        print(f"Error: {motion_info.status_code} - {motion_info.text}")
    

    url = "https://10.0.2.2:8443/automation/api/v2/events/subID"
    stream_response = requests.get(url, headers=head, verify=False, stream=True)
    client = sseclient.SSEClient(stream_response)

    # Loop forever (while connection "open")
    for event in client.events():
        print ("got a new event from server")
        pprint.pprint(event.data)

 

View original
10 replies