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

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

This exception means that youre trying to construct a dict from an iterable, and that iterables 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

… its trying to use the first element as a key-value pair—that is, a sequence of 2 values—but theres 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 whats on this page, but this code is clearly wrong:

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

I cant imagine why youd want to stream a set.

Plus, the examples all have either a dict, or a string thats 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 youre passing it a set. So, it feeds that set to the dict constructor, and gets this exception.

Since I have no idea what youre 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 youre using Plotly Cloud. But, as the same page says:

Streaming is no longer supported in Plotly Cloud.

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

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

Leave a Reply

Your email address will not be published.