401 Unauthorised Error on API calls

Hi,

I am getting 401 errors when I try to access Lasair through the API with Python. Seems to be happening with both my ZTF and LSST API keys. Not quite sure where the issue is, but I’ve tried on both my local machine and SSH’d into a different machine so it’s not an IP or MAC address blacklisting issue – at least I don’t think!

I’d appreciate whatever help you can to help me chase this down.

Thanks,

Chris

Hi Chris,

I’ve just tested your token and I can confirm that it appears to work fine (this is for Lasair-LSST - I can check ZTF as well if you like). The most common reason for 401 errors is confusion over endpoints: you should have a line where you set up the client that looks something like

L = lasair(my_api_token, endpoint="https://api.lasair.lsst.ac.uk/api")

That’s the correct value for Lasair-LSST. The equivalent for ZTF is https://lasair-ztf.lsst.ac.uk/api.

Although the endpoint parameter is technically optional, it’s best to set it explicitly so that it’s clear which server you’re connecting to; the default value was changed at some point so it depends what version of the client you have installed. Can you please check what endpoint you’re using and let me know?

@cduffy, as a forum moderator, I’ve marked Paula’s response as the solution since it seems to address your question. But could you confirm whether you are still getting 401 errors, or is everything working now?

Hi @galaxyumi331, yes that solves things for me. Thanks @gpfrancis it was the endpoint option that I was missing when I setup the client.