# Client connection Forbidden

**URL:** <https://forum.alpaca.markets/t/client-connection-forbidden/11066>\
**Category:** Getting Started with Alpaca\
**Created:** [November 13, 2022, 10:15pm UTC](https://forum.alpaca.markets/t/client-connection-forbidden/11066 "2022-11-13T22:15:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stocker](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/stocker/32/4827_2.png) [@Stocker](https://forum.alpaca.markets/u/Stocker)\
**Post date:** [November 13, 2022, 10:15pm UTC](https://forum.alpaca.markets/t/client-connection-forbidden/11066/1 "2022-11-13T22:15:28Z")

</div>

I just started using Alpaca API. I had no problem using the old, soon-deprecated alpaca\_trade\_api, but when trying the new alpaca-py package, I got the error {“message”: “forbidden”}

The code looks like:

client = StockHistoricalDataClient(‘ALPACA\_API\_KEY’, ‘ALPACA\_SECRET\_KEY’)

request\_params = StockBarsRequest(  
symbol\_or\_symbols=[“AAPL”],  
timeframe=TimeFrame.Day,  
start=datetime.datetime.strptime(“2022-07-01”, ‘%Y-%m-%d’),  
end=datetime.datetime.strptime(“2022-07-07”, ‘%Y-%m-%d’)  
)

D = client.get\_stock\_bars(request\_params)

The explicit error message is:  
HTTPError: 403 Client Error: Forbidden for url: [https://data.alpaca.markets/v2/stocks/bars?start=2022-07-01T00%3A00%3A00Z&end=2022-07-07T00%3A00%3A00Z&timeframe=1Day&symbols=AAPL](https://data.alpaca.markets/v2/stocks/bars?start=2022-07-01T00%3A00%3A00Z&end=2022-07-07T00%3A00%3A00Z&timeframe=1Day&symbols=AAPL)

Curiously, I got no error with crypto data client if I don’t use keys and secrets:

client = StockHistoricalDataClient()

request\_params = StockBarsRequest(  
symbol\_or\_symbols=[“AAPL”],  
timeframe=TimeFrame.Day,  
start=datetime.datetime.strptime(“2022-07-01”, ‘%Y-%m-%d’),  
end=datetime.datetime.strptime(“2022-07-07”, ‘%Y-%m-%d’)  
)

D = client.get\_stock\_bars(request\_params)

But, if I do use my key and secret, I got a similar forbidden error message. The only difference seems to be that the crypto function calls a v1beta2 URL, not the V2 url:  
HTTPError: 403 Client Error: Forbidden for url: [https://data.alpaca.markets/v1beta2/crypto/bars?start=2022-09-01T00%3A00%3A00Z&end=2022-09-07T00%3A00%3A00Z&timeframe=1Day&symbols=BTC%2FUSD](https://data.alpaca.markets/v1beta2/crypto/bars?start=2022-09-01T00%3A00%3A00Z&end=2022-09-07T00%3A00%3A00Z&timeframe=1Day&symbols=BTC%2FUSD)

Can Alpaca please explain what is going on? Thanks.
