Forums

API not being authenticated in live web app but works fine in console and local server

Hi, I'm using the EasyPost API in my web app and it's not working at all when I deploy my app. It is saying that an API key or enterprise credential was not provided in the request sent ("Must provide API key or enterprise credentials when creating client"), however, when I test it from the console on PythonAnywhere or on my local machine, it works perfectly fine and returns a response.

Initially I had the keys in a .env file, but I even tried by hardcoding the key directly in the .py file, yet it's still showing this error.

What could be going wrong?

If you have the key hardcoded in your Python code, then you're either not using it correctly or you are using the wrong key.

No, I have it in a .env file. I only hardcoded it to test out what the error might be, I was getting a different error afterwards (I'll have to check back for the exact message) but either way it wasn't working. I'm not using the wrong key because the code works perfectly in the console.

How are you loading the .env file? Maybe add some logging to your app, and see if env vars from .env are correctly loaded in the web app. Also, have a look at this help page.