Replies: 3 comments 4 replies
-
Your key is missing in production. You can either add a default to the variable in production.py or export the correct variable. With a default="" your production will come to life but your openai wont work. |
Beta Was this translation helpful? Give feedback.
-
I did that, still no life. Still the same error. It doesn't appear as though the settings entry from production.py is being loaded at all and the default nor the OPENAI_API_KEY read. Puzzling. I could only imagine a typo doing this, but I have gone through a fine toothcomb making sure there are none. The exact same settings entry is read from local.py, and openai works just fine in local dev. |
Beta Was this translation helpful? Give feedback.
-
Where are you getting this error: locally or on production? You're saying that you defined the setting in UPDATE: saw your last answer after posting this |
Beta Was this translation helpful? Give feedback.
-
Hi All,
Searched discussions for similar issue, but could not find anything related.
I'm having problem with importing and using an OPENAI_API_KEY stored in my .envs/.production/django file.
I have the following in the production.py
OPENAI_API_KEY = env('OPENAI_API_KEY')
and this in the .production file:
OPENAI_API_KEY=sk-<some_api_key>
and calling it like such in my utils.py:
I've also tried
client = OpenAI(api_key)
and got the same result.The result:
AttributeError: 'Settings' object has no attribute 'OPENAI_API_KEY'
when I try to build on the production server. The same setup worked just fine locally.I am running both local and production via Docker.
Stuck on this for the last few hours, and I'd appreciate any pointers.
Beta Was this translation helpful? Give feedback.
All reactions