plotly: TypeError: cannot convert dictionary update sequence element #0 to a sequence

This exception means that you’re trying to construct a dict from an iterable, and that iterable’s first element is not a sequence. As the docs explain, you can construct a dict two ways:

  • From a mapping, or
  • From an iterable of key-value pairs

So, if you try to construct it from, say, a set of numbers:

>>> dict({1, 2, 3})
TypeError: cannot convert dictionary update sequence element #0 to a sequence

… it’s trying to use the first element as a key-value pair—that is, a sequence of 2 values—but there’s no way to interpret the number 1 as a key-value pair, so it raises a TypeError.


Meanwhile, I know absolutely nothing about Plotly streaming but what’s on this page, but this code is clearly wrong:

stream1.write({dateTime,tempt,humty})

I can’t imagine why you’d want to stream a set.

Plus, the examples all have either a dict, or a string that’s a JSON-encoding of a dict.

So, obviously, that API is expecting you to pass it either a dict or something you can feed to the dict constructor. But you’re passing it a set. So, it feeds that set to the dict constructor, and gets this exception.

Since I have no idea what you’re actually trying to do here, I have no idea what dict you should be sending here. But you definitely should be passing a dict.


Also, even if you fix this, based on the sign_in call, it looks like you’re using Plotly Cloud. But, as the same page says:

Streaming is no longer supported in Plotly Cloud.

So, if you’re trying to use streaming with Plotly Cloud, then, even if you fix your code to make sense, it’s probably still going to fail, just with an error from Plotly rather than a TypeError about passing nonsense.

Leave a Comment