# requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://paper-api.alpaca.markets/v2/positions

**URL:** <https://forum.alpaca.markets/t/requests-exceptions-httperror-403-client-error-forbidden-for-url-https-paper-api-alpaca-markets-v2-positions/16479>\
**Category:** Alpaca Trading\
**Created:** [March 18, 2025, 4:00pm UTC](https://forum.alpaca.markets/t/requests-exceptions-httperror-403-client-error-forbidden-for-url-https-paper-api-alpaca-markets-v2-positions/16479 "2025-03-18T16:00:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sarahvignale](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@sarahvignale](https://forum.alpaca.markets/u/sarahvignale)\
**Post date:** [March 18, 2025, 4:00pm UTC](https://forum.alpaca.markets/t/requests-exceptions-httperror-403-client-error-forbidden-for-url-https-paper-api-alpaca-markets-v2-positions/16479/1 "2025-03-18T16:00:53Z")

</div>

Hi,

I am repeatedly getting the 403 forbidden error. As per [this](https://forum.alpaca.markets/t/403-client-error-forbidden-for-url/4118/8), the basic issue looks to be a mismatch of keys and urls (I have a paid subscription and the keys are not stale, so this looks to be the only way this could happen).

I am pasting my relevant piece of code here. Can someone check and see whether this is correct or not (this has been borrowed heavily from [this link](https://alpaca.markets/learn/how-to-trade-options-with-alpaca)):

================  
TRADE\_API\_KEY = ‘PAPER KEY’  
TRADE\_API\_SECRET = ‘PAPER SECRET KEY’  
TRADE\_API\_URL = “[https://api.alpaca.markets](https://api.alpaca.markets)”

CLIENT = OptionHistoricalDataClient(TRADE\_API\_KEY, TRADE\_API\_SECRET)  
CLIENT\_STOCK = StockHistoricalDataClient(TRADE\_API\_KEY, TRADE\_API\_SECRET)

PAPER = True  
if PAPER:  
TRADE\_CLIENT =  
TradingClient(api\_key=TRADE\_API\_KEY, secret\_key=TRADE\_API\_SECRET, paper=PAPER, url\_override=None)  
else:  
TRADE\_CLIENT = TradingClient(api\_key=TRADE\_API\_KEY, secret\_key=TRADE\_API\_SECRET, paper=PAPER, url\_override=TRADE\_API\_URL)

====================

What exactly is wrong with this piece of code?

Thanks

---

<div class="post-metadata">

**Author:** ![sarahvignale](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@sarahvignale](https://forum.alpaca.markets/u/sarahvignale)\
**Post date:** [March 20, 2025, 4:24pm UTC](https://forum.alpaca.markets/t/requests-exceptions-httperror-403-client-error-forbidden-for-url-https-paper-api-alpaca-markets-v2-positions/16479/2 "2025-03-20T16:24:08Z")

</div>

I have been querying current positions and repeatedly closing them in my script and all these problems happen when I do the same. I place some orders and in order to measure the effectiveness of my strategy, I immediately go over the positions object, see the price in which I got filled and then close out my current positions so that I can do the same analysis for my next trade afresh.

These problems happen when I continually query my positions and close them out.

Now, I have come up with a new approach in which I will simply place these trades and measure their effectiveness post market close, by getting current positions. This way, I do not need to continually query current positions and close them. I believe that this approach makes sense.

Just updating so that it will be helpful for everyone.
