403 Client Error: Forbidden for url

Hi there,

Got a 403 Client Error: Forbidden url with the below Python program:

import pandas as pd
import alpaca_trade_api as tradeapi
api = tradeapi.REST(api_version=‘v2’)
result = api.get_barset(‘AAPL’, ‘minute’, start = ‘2021-01-28’, end = ‘2021-01-28’).df
print(result)

Response: requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://data.alpaca.markets/v1/bars/minute?symbols=AAPL&start=2021-01-28&end=2021-01-28

Any idea what is causing this?

Ebel

I intermittently get the same thing for the following url:
https://paper-api.alpaca.markets/v2/orders

I’m also looking for ideas on what could be causing this type of error.

Joel

I also get the same error. get_bars or get_barset show the 403 error: “Forbidden for url: https://data.alpaca.markets
alpaca.get_bars("AAPL", TimeFrame.Day, "2021-08-01", "2021-08-30", limit=10, adjustment='raw')

Somehow all other requests are working: alpaca.list_positions() or alpaca.get_account()

Is it about free plan? Pls advise.

Sorry for bothering. I needed to generate new paper account key. Old probably was too old.

same issue, how did you resolve it.

I didn’t quite see the API and SECRET key being passed

api = tradeapi.REST(API_KEY, SECRET_KEY, BASE_URL, api_version=“v2”)

Base URL as “https://paper-api.alpaca.markets”?

hi, how you solve it?

@Mirex A ‘Forbidden’ error is most likely one of three things 1) the API key/secret key are old or incorrect 2) the API key/secret key/ base url don’t align (eg one is using their paper API keys but accessing the live base url or 3) for market data one only has a Free subscription but is trying to access features only available in an “Unlimited” subscription.

2 Likes

I have a GO example of a forbidden error.
The issue that the code is not correct in the documentation:

	alpaca.PlaceOrder(alpaca.PlaceOrderRequest{
		AssetKey: &symbol,
		Qty: decimal.NewFromFloat(1),
		Side: alpaca.Buy,
		Type: alpaca.Market,
		TimeInForce: alpaca.Day,
	})

This code uses DefaultClient which doesn’t have API keys and so on

U need to use this code

func main() {
	client := alpaca.NewClient(alpaca.ClientOpts{
		// Alternatively you can set your key and secret using the
		// APCA_API_KEY_ID and APCA_API_SECRET_KEY environment variables
		APIKey:    "YOUR_API_KEY",
		APISecret: "YOUR_API_SECRET",
		BaseURL:   "https://paper-api.alpaca.markets",
	})
	acct, err := client.GetAccount()
	if err != nil {
		panic(err)
	}
	fmt.Printf("%+v\n", *acct)

buyOrder, err := client.PlaceOrder(alpaca.PlaceOrderRequest{
		Symbol:      symbol,
		Qty:         &qty,
		Side:        alpaca.Buy,
		Type:        alpaca.Market,
		TimeInForce: alpaca.Day,
	})

}

Found out this a credentials key problem especially when installing a new set of keys after discarding some older ones. First I waited coupla minutes for new keys to populate, second I ensured the config file etc was properly copied new keys. Saved the whole lot and completely shut down my jupyter notebook and restarted the programs. Worked. I believe the old keys remained in the system and needed to be purged completely.