# Keep getting CancelledError

**URL:** <https://forum.alpaca.markets/t/keep-getting-cancellederror/1678>\
**Category:** Alpaca Integration Applications\
**Created:** [June 3, 2020, 3:26pm UTC](https://forum.alpaca.markets/t/keep-getting-cancellederror/1678 "2020-06-03T15:26:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josh\_Raisher](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/josh_raisher/32/856_2.png) [@Josh\_Raisher](https://forum.alpaca.markets/u/Josh_Raisher)\
**Post date:** [June 3, 2020, 3:26pm UTC](https://forum.alpaca.markets/t/keep-getting-cancellederror/1678/1 "2020-06-03T15:26:42Z")

</div>

I’m trying to get the Alpaca Momentum Trading Example script to work, and I’ve ironed out most of the issues. But it still randomly (usually after 20-30 minutes) throws an asyncio.exceptions.CancelledError and shuts down.

 ![error2](https://us1.discourse-cdn.com/flex020/uploads/alp/original/1X/0ca0bdb4588a0ae5cb41c163ab788e8a789f6ea4.jpeg)

Since the script needs to run the whole time the market is open, that’s obviously a big problem 🙂  
I’m pretty familiar with Python but a total noob at websockets and streaming. Anyone know what’s happening, and how to fix it?

---

<div class="post-metadata">

**Author:** ![Randy\_McClellan1](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/randy_mcclellan1/32/360_2.png) [@Randy\_McClellan1](https://forum.alpaca.markets/u/Randy_McClellan1)\
**Post date:** [July 8, 2020, 7:20pm UTC](https://forum.alpaca.markets/t/keep-getting-cancellederror/1678/2 "2020-07-08T19:20:29Z")

</div>

did you figure this out? I am running into the same issue.

Thanks,  
Randy

---

<div class="post-metadata">

**Author:** ![Shlomik](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/shlomik/32/793_2.png) [@Shlomik](https://forum.alpaca.markets/u/Shlomik)\
**Post date:** [August 2, 2020, 1:26pm UTC](https://forum.alpaca.markets/t/keep-getting-cancellederror/1678/3 "2020-08-02T13:26:21Z")

</div>

Hi guys, these happen when server communication disconnects.  
we handled this by trying to reconnect when it happens in the most updated version of the sdk  
install the latest version by running `pip install -U alpaca-trade-api`

---

<div class="post-metadata">

**Author:** ![dexterdce](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@dexterdce](https://forum.alpaca.markets/u/dexterdce)\
**Post date:** [September 3, 2020, 4:52pm UTC](https://forum.alpaca.markets/t/keep-getting-cancellederror/1678/4 "2020-09-03T16:52:00Z")

</div>

The error is still not fixed. Updated to the latest version but I also keep getting the same error
