我正在尝试将Azure机器学习服务中的Azure SQL数据库与MSI身份验证(没有用户名和密码)连接起来。
我正在尝试在azure机器学习服务上使用机器学习模型,目的是我需要数据,这就是为什么我想使用MSI身份验证从Azure机器学习服务连接Azure SQL数据库的原因。
但是我得到以下错误:-
"error": {"message": "Activity Failed:\n{\n \"error\": {\n \"code\": \"UserError\",\n \"message\": \"User program failed with KeyError: 'MSI_ENDPOINT'\",\n
请检查以下我用于数据库连接的代码。
import logging
import struct
import pyodbc
import os
import requests
class AzureDbConnect:
def __init__(self):
print("Inside msi database")
msi_endpoint = os.environ["MSI_ENDPOINT"]
msi_secret = os.environ["MSI_SECRET"]
resource_uri = 'https://database.windows.net/'
logging.info(msi_endpoint)
print(msi_endpoint)
logging.info(msi_secret)
print(msi_secret)
print("Inside token")
token_auth_uri = f"{msi_endpoint}?resource={resource_uri}&api-version=2017-09-01"
head_msi = {'Secret': msi_secret}
resp = requests.get(token_auth_uri, headers=head_msi)
access_token = resp.json()['access_token']
logging.info(access_token)
print("Token is :- ")
print(access_token)
accesstoken = bytes(access_token, 'utf-8')
exptoken = b""
for i in accesstoken:
exptoken += bytes({i})
exptoken += bytes(1)
tokenstruct = struct.pack("=i", len(exptoken)) + exptoken
conn = pyodbc.connect("Driver={ODBC Driver 17 for SQL Server};"
"Server=tcp:<Server Name>"
"1433;Database=<Database Name>",
attrs_before={1256: bytearray(tokenstruct)})
print(conn)
self.sql_db = conn.cursor()
是否可以通过MSI身份验证从Azure机器学习服务连接Azure,SQL数据库?] >>
我正在尝试使用MSI身份验证(没有用户名和密码)连接来自Azure机器学习服务的Azure SQL数据库。我正在尝试在azure机器上进行机器学习模型...