Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

Py.stream not connected

Hi,
when trying the standard streaming-example (the getting started one) The scatter plot gets created, but once I try to open the stream it fails to stream the following data and s.connected is false.

Here is the total code I use:

import numpy as np
import plotly.plotly as py
import plotly.tools as tls
import plotly.graph_objs as go
import datetime
import time

stream_ids = tls.get_credentials_file()['stream_ids']
print stream_ids

# Get stream id from stream id list
stream_id = stream_ids[0]

# Make instance of stream id object
stream_1 = go.Stream(
     token=stream_id,  # link stream id to 'token' key
    maxpoints=80      # keep a max of 80 pts on screen
)  

# stream_1 = dict(token=stream_id, maxpoints=60)

# Initialize trace of streaming plot by embedding the unique stream_id
trace1 = go.Scatter(
    x=[],
    y=[],
    # mode='line+markers',
    stream=stream_1         # (!) embed stream id, 1 per trace
)

data = go.Data([trace1])

# Add title to layout object
layout = go.Layout(title='Time Series')

# Make a figure object
fig = go.Figure(data=data, layout=layout)

# Send fig to Plotly, initialize streaming plot, open new tab
# py.iplot(fig, filename='python-streaming')
py.plot(fig, filename='python-streaming')

# We will provide the stream link object the same token that's associated with the trace we wish to stream to
s = py.Stream(dict(stream_id=stream_1))

# We then open a connection
s.open()
# s.heartbeat()

print "Is connected: ", s.connected

i = 0    # a counter
k = 5    # some shape parameter

# Delay start of stream by 5 sec (time to switch tabs)
time.sleep(5)

j = 0
while j < 5:
    # Current time on x-axis, random numbers on y-axis
    x = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
    y = (np.cos(k*i/50.)*np.cos(i/50.)+np.random.randn(1))[0]

    print "data %s: %f" % (str(x), y)

    # Send data to your plot
    s.write(dict(x=x, y=y))

    #     Write numbers to stream to append current data on plot,
    #     write lists to overwrite existing data on plot

    time.sleep(1)  # plot a point every second
    j += 1
# Close the stream when done plotting
s.close()

To clarify: I do not get any error message. The plot called Timeseries shows up (but without data) and the loop finishes without error. s.connected is false

I am stuck