Can't start because of a Error

Hello,
Sorry for my english, i’m French.
I want to start to code my trading bot for fun. So i use a Paper Account.
When i want to execute my first line of code just for see my account, i have this Error.

requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://paper-api.alpaca.markets/v2/account

and this error :

alpaca_trade_api.rest.APIError: request is not authorized

I have already try to change my Code editor or to regenerate my API KEY.

My code is :

from keyetcc import*
import alpaca_trade_api as tradeapi

# authentication and connection details
api_key = 'API_KEY'
api_secret = 'API_SECRET_KEY'
base_url = 'https://paper-api.alpaca.markets'

# instantiate REST API
api = tradeapi.REST(api_key, api_secret, base_url, api_version='v2')

# obtain account information
account = api.get_account()
print(account)

Thank for you Help !
Have a nice day

I have also been having this error which also occurs when using the Alpaca examples

So anyone has a solution ??

I really want to start this fun project but i have not find

I was having similar problems using code from one of the video examples.

I used your code and put the API_KEY and SECRET_KEY directly into the variable.

That worked.

I have been trying to get access as well and getting the same error: b’{“code”:40110000,“message”:“request is not authorized”}’

I have followed Larry’s Python code running from the Terminal and Spyder getting the same message. My code is simple:
import requests
from config import API_KEY, SECRET_KEY

BASE_URL = ‘https://paper-api.alpaca.markets
ACCOUNT_URL = “{}/v2/account”.format(BASE_URL)

r = requests.get(ACCOUNT_URL, headers={‘APCA_API_KEY_ID’: API_KEY, ‘APCA_API_SECRET_KEY’: SECRET_KEY})
print(r.content)

Your ideas are appreciated!

@jkamp The issue is with your header names. The names should have dashes rather than underscores. Like this

r = requests.get(ACCOUNT_URL, headers={‘APCA-API-KEY-ID’: API_KEY, ‘APCA-API-SECRET-KEY’: SECRET_KEY})

Try that.