RIPE-NCC / ripe-atlas-cousteau

Python client for RIPE ATLAS API
GNU General Public License v3.0
65 stars 26 forks source link

Example code (streaming) fails #41

Closed JonasGroeger closed 7 years ago

JonasGroeger commented 7 years ago

Tried: (Python3.5, ripe.atlas.cousteau==1.2) (Python3.5, ripe.atlas.cousteau==1.3)

I'm using the example code from the README.rst file:

from ripe.atlas.cousteau import AtlasStream

def on_result_response(*args):
    """
    Function that will be called every time we receive a new result.
    Args is a tuple, so you should use args[0] to access the real message.
    """
    print(args[0])

atlas_stream = AtlasStream()
atlas_stream.connect()
# Measurement results
channel = "result"
# Bind function we want to run with every result message received
atlas_stream.bind_channel(channel, on_result_response)
# Subscribe to new stream for 1001 measurement results
stream_parameters = {"msm": 4412911}
atlas_stream.start_stream(stream_type="result", **stream_parameters)

# Timeout all subscriptions after 5 secs. Leave seconds empty for no timeout.
# Make sure you have this line after you start *all* your streams
atlas_stream.timeout()
# Shut down everything
atlas_stream.disconnect()

If I'm using the Javascript Code however, this works:


<script src="https://atlas-stream.ripe.net/socket.io.js"></script>
<script>

    // Create a connection (it can be also http on port 80)
    var socket = io("https://atlas-stream.ripe.net:443", { path : "/stream/socket.io" });

    // Subscribe to results coming from all the probes involved in the measurement 4412911
    socket.emit("atlas_subscribe", { stream_type: "result", msm: 4412911 });

    // Declare a callback to be executed when a measurement result is received
    socket.on("atlas_result", function(result){
        console.log("I received ", result);
    });

</script>

In case of the python script, the function on_result_response is not called at all. The console.log() in the javascript code however works fine.

I already started digging a little bit: The port / protocol (http/https) seems not to be the issue. Any ideas?

astrikos commented 7 years ago

Hi @JonasGroeger , i just tried the above code and it seems to work with py3.4.3 and cousteau1.3. I see results. I wouldn't expect much difference with py3.5 but i am going to give it a try later. Do you see any errors using python, or it just waiting with nothing on the output?

JonasGroeger commented 7 years ago

@astrikos It works now but yesterday it didnt for quite some time. Have there been outages?

astrikos commented 7 years ago

not that i know of, maybe it was just a glitch and you were unlucky to try at the wrong time :( But I am glad you make it work now :)