If you’re running this in the learning platform you can leave the key as it is, i.e.
openai.api_key = os.environ[‘OPENAI_API_KEY’]
(do not replace the string ‘OPEN_API_KEY’)
KeyError Traceback (most recent call last)
Cell In[48], line 6
4 from dotenv import load_dotenv, find_dotenv
5 _ = load_dotenv(find_dotenv()) # read local .env file
----> 6 openai.api_key=os.environ[‘sk-Myhiddenkey’']
File ~\AppData\Local\anaconda3\lib\os.py:680, in _Environ.getitem(self, key)
677 value = self._data[self.encodekey(key)]
678 except KeyError:
679 # raise KeyError with the original key value
→ 680 raise KeyError(key) from None
681 return self.decodevalue(value)
KeyError: ‘sk-Myhiddenkey’
When i set my key directly ignoring the os.environ, it works fine, but later complains about arguments used for the os.environ function
openai.api_key=‘sk- Myhiddenkey’
Has anyone had this issue. This is at the beginning so i can not complete this course if thsi is not fixed. I think this is something todo with variabl declaration from teh prompt engineering course.
Yes, I am also having exactly the same issue.
KeyError Traceback (most recent call last)
Cell In[12], line 4
2 _ = load_dotenv(find_dotenv()) # read local .env file
3 ##OPENAI_API_KEY=‘sk-Mykey’ I was trying to assign key to this variable, but didn’t work.
----> 4 openai.api_key =os.environ[‘sk-Mykey’]
File ~\AppData\Local\anaconda3\lib\os.py:680, in _Environ.getitem(self, key)
677 value = self._data[self.encodekey(key)]
678 except KeyError:
679 # raise KeyError with the original key value
→ 680 raise KeyError(key) from None
681 return self.decodevalue(value)