Getting a Client Error: Unauthorized for url error

Hi,

I’m getting started with the Alpaca API. I’ve created a paper account about an hour ago and I’m trying to setup a simple python script. I’ve been getting an the 401 Client Error: Unauthorized for url and the access key verification failed : access key not found (Code = 40110000) errors, and I cannot figure out why. My code is straight forward:

import alpaca_trade_api as tradeapi

base_url = 'https://paper-api.alpaca.markets'
api_key_id = 'api_key_id'
api_secret = 'api_secret'

api = tradeapi.REST(
    key_id=api_key_id,
    secret_key=api_secret,
    base_url=base_url,
    api_version='v2'
)

account = api.get_account()
print(account)

I’m not a US resident, but as far as I can tell, this should work for a paper account, shouldn’t it?

I tested your code with my own paper keys and it worked. Are you sure you are using the keys from your paper account, not your live account? Also, the keys reset whenever you reset your paper account, so maybe that’s what did it? In any case, I’d try resetting your paper account and then grabbing your keys again.

1 Like

Ugh! This is embarrassing. I was looking at the app credential and not the trade credential. Thanks! Your screenshot explained where I was wrong.

1 Like