# 401 Client Error

**URL:** <https://forum.alpaca.markets/t/401-client-error/11699>\
**Category:** Alpaca Trading\
**Created:** [January 30, 2023, 3:56pm UTC](https://forum.alpaca.markets/t/401-client-error/11699 "2023-01-30T15:56:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![redcoatwright](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/redcoatwright/32/5022_2.png) [@redcoatwright](https://forum.alpaca.markets/u/redcoatwright)\
**Post date:** [January 30, 2023, 3:56pm UTC](https://forum.alpaca.markets/t/401-client-error/11699/1 "2023-01-30T15:56:20Z")

</div>

Hi, I tried submitting a trade today via the API to my paper account and I received this error:

`401 Client Error: Unauthorized for url: https://paper-api.alpaca.markets/v2/orders`

I have been designated a PDT in my paper account (and rightly so) but I have 99k in equity there so I shouldn’t be limited. I have the config for the day trading set to “Block on entry” but I think that shouldn’t apply, it just applies to when the rule is checked (if my understanding is correct).

I also regenned my API keys just in case that was the issue.

**Edit:** I should have included my code, here is what I’m doing that’s getting blocked:

```auto
        market_order_data = MarketOrderRequest(
                                symbol='SPY',
                                notional=100,
                                side=OrderSide.BUY,
                                time_in_force=TimeInForce.DAY
                            )

```

And I tried:

```auto
        market_order_data = MarketOrderRequest(
                                symbol='SPY',
                                qty=1,
                                side=OrderSide.BUY,
                                time_in_force=TimeInForce.DAY
                            )

```

But then I tried in the account GUI and it worked fine so I know it isn’t a block…

---

<div class="post-metadata">

**Author:** ![Dan\_Whitnable\_Alpaca](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/dan_whitnable_alpaca/32/1658_2.png) [@Dan\_Whitnable\_Alpaca](https://forum.alpaca.markets/u/Dan_Whitnable_Alpaca)\
**Post date:** [January 30, 2023, 7:21pm UTC](https://forum.alpaca.markets/t/401-client-error/11699/2 "2023-01-30T19:21:41Z")

</div>

@redcoatwright The 401 error you are seeing is most often an authentication issue (ie wrong keys or the wrong base URL). The PDT protections and other restrictions respond with a different error. By the fact that you can perform the order using the UI is a clue that it probably is a API key issue and not an order issue (ie the order works in the UI but doesn’t when using the API).

If you are still getting an error, ensure your API key and secret key is correct.

---

<div class="post-metadata">

**Author:** ![redcoatwright](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/redcoatwright/32/5022_2.png) [@redcoatwright](https://forum.alpaca.markets/u/redcoatwright)\
**Post date:** [January 30, 2023, 8:12pm UTC](https://forum.alpaca.markets/t/401-client-error/11699/3 "2023-01-30T20:12:01Z")

</div>

@Dan_Whitnable_Alpaca hmm but I can still use the quote API to get quotes and I’m using the alpaca-py trading client object so I’m not specifying the URL at all.

If the API keys didn’t work then I assume I wouldn’t be able to get a price quote for a security?

---

<div class="post-metadata">

**Author:** ![redcoatwright](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/redcoatwright/32/5022_2.png) [@redcoatwright](https://forum.alpaca.markets/u/redcoatwright)\
**Post date:** [January 30, 2023, 8:46pm UTC](https://forum.alpaca.markets/t/401-client-error/11699/4 "2023-01-30T20:46:16Z")

</div>

Well it started working 🤷‍♂️ so let’s nobody speak on this…
