# Unable to subscribe to stream - loop error - code included for review

**URL:** <https://forum.alpaca.markets/t/unable-to-subscribe-to-stream-loop-error-code-included-for-review/8160>\
**Category:** Alpaca Integration Applications\
**Created:** [January 27, 2022, 3:26pm UTC](https://forum.alpaca.markets/t/unable-to-subscribe-to-stream-loop-error-code-included-for-review/8160 "2022-01-27T15:26:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![livefire](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/livefire/32/4457_2.png) [@livefire](https://forum.alpaca.markets/u/livefire)\
**Post date:** [January 27, 2022, 3:26pm UTC](https://forum.alpaca.markets/t/unable-to-subscribe-to-stream-loop-error-code-included-for-review/8160/1 "2022-01-27T15:26:16Z")

</div>

Hello,

I am attempting to subscribe to a stream, but unable to get this to work. Does anyone know suggested fixes? I have 2 different types of errors:

1. When I run it without the “trade\_info” function, I get the following repetitive error:  
ERROR:root:error while consuming ws messages: As of 3.10, the _loop_ parameter was removed from Lock() since it is no longer necessary

2. When I run it with the “trade\_info” function, I get the following repetitive error:  
ERROR:root:error while consuming ws messages: unknown channel trade\_info (you may need to specify the right data\_stream)

> import alpaca\_trade\_api as tradeapi  
> import config as cfg  
> import threading
> 
> #instantiate REST API  
> api = tradeapi.REST(cfg.API\_KEY, cfg.SECRET\_KEY, base\_url=cfg.BASE\_URL, api\_version=‘v2’)
> 
> #obtain account information  
> account = api.get\_account()  
> print(account)
> 
> ws\_url = ‘wss://data.alpaca.markets’  
> conn = tradeapi.stream2.StreamConn(cfg.API\_KEY, cfg.SECRET\_KEY, base\_url=cfg.BASE\_URL,  
> data\_url=ws\_url, data\_stream=‘alpacadatav1’)
> 
> @conn.on(r’^account\_updates$')  
> async def on\_account\_updates(conn, channel, account):  
> print(‘account’, account)
> 
> @conn.on(r’^trade\_updates$')  
> async def on\_trade\_updates(conn, channel, trade):  
> print(‘trade’, trade)
> 
> @conn.on(r’^T.AAPL$')  
> async def trade\_info(conn, channel, bar):  
> print(‘bars’, bar)  
> #print(bar.\_raw)  
> print(bar.price)
> 
> def ws\_start():  
> conn.run([‘account\_updates’, ‘trade\_updates’])
> 
> #start WebSocket in a thread  
> ws\_thread = threading.Thread(target=ws\_start, daemon=True)  
> ws\_thread.start()

---

<div class="post-metadata">

**Author:** ![calvin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/calvin/32/3636_2.png) [@calvin](https://forum.alpaca.markets/u/calvin)\
**Post date:** [January 27, 2022, 5:08pm UTC](https://forum.alpaca.markets/t/unable-to-subscribe-to-stream-loop-error-code-included-for-review/8160/2 "2022-01-27T17:08:03Z")

</div>

Can you try upgrading the websockets library to 10.1? Or maybe try with python3.9?

---

<div class="post-metadata">

**Author:** ![livefire](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/livefire/32/4457_2.png) [@livefire](https://forum.alpaca.markets/u/livefire)\
**Post date:** [January 27, 2022, 5:25pm UTC](https://forum.alpaca.markets/t/unable-to-subscribe-to-stream-loop-error-code-included-for-review/8160/3 "2022-01-27T17:25:49Z")

</div>

I am still rather new working with all of this and on PyCharm. I see that my Python Interpreter is set to Python 3.10 but I don’t have any other versions I can select from. Is there an easy way to add another?

---

<div class="post-metadata">

**Author:** ![livefire](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/livefire/32/4457_2.png) [@livefire](https://forum.alpaca.markets/u/livefire)\
**Post date:** [January 27, 2022, 5:41pm UTC](https://forum.alpaca.markets/t/unable-to-subscribe-to-stream-loop-error-code-included-for-review/8160/4 "2022-01-27T17:41:41Z")

</div>

when I installed the alpaca trade api, wouldn’t the websockets library be specified to the latest?

I did upgrade to 10.1 on the websockets by installing the package, but upon re-running, same issue.

---

<div class="post-metadata">

**Author:** ![calvin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/calvin/32/3636_2.png) [@calvin](https://forum.alpaca.markets/u/calvin)\
**Post date:** [January 28, 2022, 9:16pm UTC](https://forum.alpaca.markets/t/unable-to-subscribe-to-stream-loop-error-code-included-for-review/8160/5 "2022-01-28T21:16:51Z")

</div>

Hey, I put up a PR that supports python 3.10. It’s not merged in yet, but you can still test it if you’d like.

> <https://github.com/alpacahq/alpaca-trade-api-python/pull/561>
>
> \## Context.
> Support python 3.10 by upgrading websockets library to 10.1 and rep…lacing deprecated asyncio api methods.

---

<div class="post-metadata">

**Author:** ![livefire](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/livefire/32/4457_2.png) [@livefire](https://forum.alpaca.markets/u/livefire)\
**Post date:** [January 28, 2022, 9:19pm UTC](https://forum.alpaca.markets/t/unable-to-subscribe-to-stream-loop-error-code-included-for-review/8160/6 "2022-01-28T21:19:41Z")

</div>

This is so cool of you! Thank you!
