#Bizarre .env behavior with .py vs Jupyter

4 messages · Page 1 of 1 (latest)

latent mesa
#

This just started today (8/1). Yesterday everything was fine in the same VS project.

  1. I have two files with the exact same code as a test. One is standard .py and the other is a Jupyter Notebook.
  2. All files are running in the same VS virtual environment in the same project at the root folder.
  3. One .env file in the project has all the secret keys also at the root folder.
  4. Using both 'os' and the 'dotenv' methods (individual tests), everything runs fine in the Jupyter Notebook (both VS integrated and browser-based Jupyter). JN picks up the environment variables and run perfectly.
  5. However running the exact same code in the .py file creates a "openai.error.AuthenticationError(
    openai.error.AuthenticationError: No API key provided. You can set your API key in code using 'openai.api_key = <API-KEY>" error. The exact same code as in JN.
  6. The .py will only load the "secrets" if I hard code in the API key (which of course is ill advised). Neither 'os' or 'dotenv' seem to be able to grab them from .env even though everything else is identical.

So in sum, even though everything is running in the same environment, only Jupyter picks up the secrets from the .env file even though 24 hours ago, everything worked fine (.py and JN).

Sorry for the long question but I'm at the point of lathering my misery in some bourbon. Thank you.

#

Also thought I would add that in the .py file, if I run dotenv_load() it returns True and if I run dotenv_values() it returns the dict with all the keys. dalle_tired

tiny sigil
#

I may not be able to solve your problem directly but once I met a problem in win 8 that the system decide the .env file as illegal because it doesn't have a file name.

#

I wonder whether it is because of this