This has randomly happened to me, but it appears to be related to the /bars/ endpoint:
Traceback (most recent call last):
File “/usr/local/lib/python3.8/site-packages/alpaca_trade_api/rest.py”, line 140, in _one_request
resp.raise_for_status()
File “/usr/local/lib/python3.8/site-packages/requests/models.py”, line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://data.alpaca.markets/v1/bars/day?symbols=TLRY%2CSPWR%2CMP%2CMARA%2CGME&limit=20
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py”, line 34, in inner
response = get_response(request)
File “/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py”, line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File “/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py”, line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File “/usr/local/lib/python3.8/site-packages/django/utils/decorators.py”, line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File “/usr/local/lib/python3.8/site-packages/django/contrib/auth/decorators.py”, line 21, in _wrapped_view
return view_func(request, *args, **kwargs)
File “/ap/alpaca/views.py”, line 223, in positions
bars = api_test.get_barset(sym_list, ‘day’, 20)
File “/usr/local/lib/python3.8/site-packages/alpaca_trade_api/rest.py”, line 456, in get_barset
resp = self.data_get(’/bars/{}’.format(timeframe), params)
File “/usr/local/lib/python3.8/site-packages/alpaca_trade_api/rest.py”, line 172, in data_get
return self._request(
File “/usr/local/lib/python3.8/site-packages/alpaca_trade_api/rest.py”, line 119, in _request
return self._one_request(method, url, opts, retry)
File “/usr/local/lib/python3.8/site-packages/alpaca_trade_api/rest.py”, line 148, in _one_request
raise APIError(error, http_error)
alpaca_trade_api.rest.APIError: token is not authorized for this scope (Code = 40110000)