我正在执行本教程中的代码: https://learn.microsoft.com/en-us/azure/machine-learning/tutorial-deploy-model?view=azureml-api-2
这应该从我已经注册的模型部署端点。 然而我收到这个错误:
HttpResponseError:(InvalidSubscriptionId)提供的订阅标识符“”格式错误或无效。
代码:无效订阅ID
消息:提供的订阅标识符“”格式错误或无效。
特别是代码中的这两行抛出此错误:
endpoint = ml_client.online_endpoints.begin_create_or_update(endpoint).result()
endpoint = ml_client.online_endpoints.get(name=online_endpoint_name)
订阅 ID 绝对没有任何问题,我无法弄清楚这一点。
是否有可能在应该调用 HTTPS 的时候调用 HTTP?
我尝试重试订阅 ID,没有任何问题,甚至尝试了不同的工作区。
我不认为这是身份验证问题,我能够与其他项目连接。
使用不同的 ml_client 实例化器解决了该问题。
Write it to JSON in notebooks:
%%writefile workspace.json
{
"subscription_id": "6f247126-9881-4267-9635-80cd63c7b5a1",
"resource_group": "Candidate_5_GenAI",
"workspace_name": "candidate_5_gen_ai"
}
然后像这样定义您的工作区,而不是像教程中那样:
from azure.identity import DefaultAzureCredential, InteractiveBrowserCredential
from azure.ai.ml import MLClient, Input, Output
from azure.ai.ml.constants import AssetTypes
from azure.ai.ml.dsl import pipeline
from azureml.core import Workspace
try:
credential = DefaultAzureCredential()
# Check if given credential can get token successfully.
credential.get_token("https://management.azure.com/.default")
except Exception:
# Fall back to InteractiveBrowserCredential in case DefaultAzureCredential not work
credential = InteractiveBrowserCredential()
try:
ml_client = MLClient.from_config(credential=credential, path="workspace.json")
except Exception as ex:
raise Exception(
"Failed to create MLClient from config file. Please modify and then run the above cell with your AzureML Workspace details."
) from ex
# ml_client = MLClient(
# credential=credential,
# subscription_id="",
# resource_group_name="",
# workspace_name=""
# )
ws = Workspace(
subscription_id=ml_client.subscription_id,
resource_group=ml_client.resource_group_name,
workspace_name=ml_client.workspace_name,
)
ml_client