I’m having a persistent authentication issue with the Market Data API that I haven’t been able to resolve after extensive troubleshooting.
Account type: Paper trading
Issue:
Requests to the Trading API (paper-api.alpaca.markets) authenticate successfully — I can retrieve account info and it works as expected.
However, requests to the Market Data API (data.alpaca.markets) consistently return a 401 Unauthorized error, but notably as a raw nginx HTML page rather than Alpaca’s standard JSON error format:
@rblackman50 A 401 error means your API key and/or secret is incorrect. There are a few other causes (such as using the wrong base URL or incorrect header names), but if you are using the alpaca-py SDK those will not be an issue.
The first thing to verify is that you are actually using the API key and secret that you expect. You may want to print out those values immediately before you instantiate your StockHistoricalDataClient. Perhaps like this
I can check the logs, which often contain helpful information if you provide an approximate time (including time zone) and the exact call you are making. For instance