英文:
Problems with OpenAI Authentification
问题
I've translated the non-code part of your text as you requested:
"I've got some problems with the Authentification to OpenAI in my python code. It seems like, OpenAI doesn't accept my key. I did a new one and tried it with other ones before. I always get the same issues. I just copied and pasted the key, same for the organization. There isn't a typo. There is another problem, but I don't know why the authentication failed.
Here is my code:
I used it in the same way like the OpenAI Website https://platform.openai.com/docs/api-reference/authentication?lang=python"
If you need assistance with the code or have further questions, feel free to ask.
英文:
I've got some problems with the Authentification to OpenAI in my python code. It seems like, OpenAI doesn't accept my key. I did a new on and tried it with other ones before. I always get the same issues. I just copied and pasted the key, same for the organization. There isn't a typo. There is another problem, but I don't know, why the authentifitaion failed.
Here is my code:
I used it in the same way like the OpenAI Website https://platform.openai.com/docs/api-reference/authentication?lang=python
import os
import openai
openai.organization = "org-CXk0SUzbnyzzCLcaSBCFAV64"
openai.api_key = os.getenv("sk-**********************************************9Q")
openai.Model.list()
It produces the follwing error:
openai.error.AuthenticationError: No API key provided. You can set your API key in code using 'openai.api_key = <API-KEY>', or you can set the environment variable OPENAI_API_KEY=<API-KEY>). If your API key is stored in a file, you can point the openai module at it with 'openai.api_key_path = <PATH>'. You can generate API keys in the OpenAI web interface. See https://onboard.openai.com for details, or email support@openai.com if you have any questions.
Did anyone had the some issues before? Are there any solutions?
答案1
得分: 0
您的环境变量就像一个字典,用于检索的代码应该与示例代码匹配:
openai.api_key = os.getenv("OPENAI_API_KEY")
但是,您必须首先设置环境键。
从您的代码看,似乎您只想硬编码该值,这种情况下,您的代码应该如下所示:
import openai
openai.organization = "org-CXk0SUzbnyzzCLcaSBCFAV64"
openai.api_key = "sk-**********************************************9Q"
openai.Model.list()
英文:
Your environment variables are like a dictionary, and the code to retrieve should match the sample code:
openai.api_key = os.getenv("OPENAI_API_KEY")
However, you have to set the environment keys first.
From your code, it looks like you just want to hard code the value, in which case your code should look like:
import openai
openai.organization = "org-CXk0SUzbnyzzCLcaSBCFAV64"
openai.api_key = "sk-**********************************************9Q"
openai.Model.list()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论