TypeError: Object of type set is not JSON serializable

Hi all, I tried searching the forums and on Google but couldn’t find this particular issue I noticed in my logs while paper trading. It seems to me the API would randomly disconnect and after reconnecting generate this log. Could someone clarify/suggest a solution? Here’s an example of the log

04-Jan-21 12:55:07.715 - connected to: wss://paper-api.alpaca.markets/stream

04-Jan-21 12:55:07.729 - connected to: wss://paper-api.alpaca.markets/stream

04-Jan-21 12:55:07.747 - Task exception was never retrieved
future: <Task finished name=‘Task-56’ coro=<_StreamConn._ensure_ws() done, defined at C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\alpaca_trade_api\stream2.py:86> exception=TypeError(‘Object of type set is not JSON serializable’)>
Traceback (most recent call last):
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\alpaca_trade_api\stream2.py”, line 94, in _ensure_ws
await self.subscribe(self._streams)
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\alpaca_trade_api\stream2.py”, line 110, in subscribe
await self.ws.send(json.dumps({
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\json_init
.py", line 231, in dumps
return _default_encoder.encode(obj)
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\json\encoder.py”, line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\json\encoder.py”, line 257, in iterencode
return _iterencode(o, 0)
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\json\encoder.py”, line 179, in default
raise TypeError(f’Object of type {o.class.name} ’
TypeError: Object of type set is not JSON serializable
04-Jan-21 12:55:09.765 - error while consuming ws messages: Object of type set is not JSON serializable

And here’s another example from the same day

04-Jan-21 15:02:07.689 - code = 1006 (connection closed abnormally [internal]), no reason

04-Jan-21 15:02:07.827 - code = 1006 (connection closed abnormally [internal]), no reason

04-Jan-21 15:02:14.858 - connected to: wss://paper-api.alpaca.markets/stream

04-Jan-21 15:02:14.864 - Task exception was never retrieved
future: <Task finished name=‘Task-76’ coro=<_StreamConn._ensure_ws() done, defined at C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\alpaca_trade_api\stream2.py:86> exception=TypeError(‘Object of type set is not JSON serializable’)>
Traceback (most recent call last):
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\alpaca_trade_api\stream2.py”, line 94, in _ensure_ws
await self.subscribe(self._streams)
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\alpaca_trade_api\stream2.py”, line 110, in subscribe
await self.ws.send(json.dumps({
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\json_init
.py", line 231, in dumps
return _default_encoder.encode(obj)
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\json\encoder.py”, line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\json\encoder.py”, line 257, in iterencode
return _iterencode(o, 0)
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\json\encoder.py”, line 179, in default
raise TypeError(f’Object of type {o.class.name} ’
TypeError: Object of type set is not JSON serializable
04-Jan-21 15:02:17.741 - connected to: wss://paper-api.alpaca.markets/stream

04-Jan-21 15:02:17.742 - error while consuming ws messages: Object of type set is not JSON serializable

04-Jan-21 15:02:18.632 - connected to: wss://paper-api.alpaca.markets/stream

04-Jan-21 15:02:18.669 - connected to: wss://paper-api.alpaca.markets/stream

04-Jan-21 15:02:18.670 - Task exception was never retrieved
future: <Task finished name=‘Task-78’ coro=<_StreamConn._ensure_ws() done, defined at C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\alpaca_trade_api\stream2.py:86> exception=TypeError(‘Object of type set is not JSON serializable’)>
Traceback (most recent call last):
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\alpaca_trade_api\stream2.py”, line 94, in _ensure_ws
await self.subscribe(self._streams)
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\alpaca_trade_api\stream2.py”, line 110, in subscribe
await self.ws.send(json.dumps({
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\json_init
.py", line 231, in dumps
return _default_encoder.encode(obj)
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\json\encoder.py”, line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\json\encoder.py”, line 257, in iterencode
return _iterencode(o, 0)
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\json\encoder.py”, line 179, in default
raise TypeError(f’Object of type {o.class.name} ’
TypeError: Object of type set is not JSON serializable

I submitted a fit in this PR: https://github.com/alpacahq/alpaca-trade-api-python/pull/352