You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm encountering an AuthenticationError with error code 401 when running my script in a Fabric notebook. The error message is as follows:
AuthenticationError: Error code: 401 - {‘statusCode’: 401, ‘message’: ‘Unauthorized. Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.com), or have expired.’}
This error only occurs when executing the script in the Fabric notebook environment. When I run the same script locally, it works without any issues.
import os
from openai import AzureOpenAI
endpoint = os.getenv("ENDPOINT_URL", "my url")
deployment = os.getenv("DEPLOYMENT_NAME", "gpt-35-turbo")
subscription_key = os.getenv("AZURE_OPENAI_API_KEY", "my key")
print("Assistant: You are an AI assistant that helps people find information.")
user_prompt = "Does Azure OpenAI support customer managed keys?"
answer = ask_azure_openai(user_prompt)
print(f"Assistant: {answer}")
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm encountering an
AuthenticationError
with error code 401 when running my script in a Fabric notebook. The error message is as follows:AuthenticationError: Error code: 401 - {‘statusCode’: 401, ‘message’: ‘Unauthorized. Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.com), or have expired.’}
This error only occurs when executing the script in the Fabric notebook environment. When I run the same script locally, it works without any issues.
import os
from openai import AzureOpenAI
endpoint = os.getenv("ENDPOINT_URL", "my url")
deployment = os.getenv("DEPLOYMENT_NAME", "gpt-35-turbo")
subscription_key = os.getenv("AZURE_OPENAI_API_KEY", "my key")
client = AzureOpenAI(
azure_endpoint=endpoint,
api_key=subscription_key,
api_version="2024-05-01-preview",
)
conversation_history = []
def ask_azure_openai(prompt):
conversation_history.append({"role": "user", "content": prompt})
completion = client.chat.completions.create(
model=deployment,
messages=conversation_history,
max_tokens=800,
temperature=0.7,
top_p=0.95,
frequency_penalty=0,
presence_penalty=0,
stop=None,
stream=False
)
response = completion.choices[0].message["content"].strip()
conversation_history.append({"role": "assistant", "content": response})
return response
print("Assistant: You are an AI assistant that helps people find information.")
user_prompt = "Does Azure OpenAI support customer managed keys?"
answer = ask_azure_openai(user_prompt)
print(f"Assistant: {answer}")
Beta Was this translation helpful? Give feedback.
All reactions