401 Unauthorized

Hi, keys not working.

“”"
Put secret Keys as environment variables
“”"
import os

ALPACA_ENDPOINT = “https://paper-api.alpaca.markets
ALPACA_KEYID = “PK22QG1PVWFX958PYZRN”
ALPACA_SECRETKEY = “C6lND0w0FmaKkyIGE66zWIvatiWCKk13dp8y7B5s”

os.environ[“APCA_API_KEY_ID”] = ALPACA_KEYID
os.environ[“APCA_API_SECRET_KEY”] = ALPACA_SECRETKEY
os.environ[“APCA_API_BASE_URL”] = ALPACA_ENDPOINT

requests.exceptions.HTTPError: 401 Client Error: Unauthorized

import alpaca_trade_api as tradeapi

base_url = 'https://paper-api.alpaca.markets'
api_key_id = # what ever your key is
api_secret = # what ever you key is
api = tradeapi.REST(base_url=base_url,key_id=api_key_id,secret_key=api_secret,api_version='v2')

Hope this fixes your problem.