Пока
- < li>Зарегистрировало приложение в Azure с этими разрешениями API.
- Затем создал секрет для моего субъекта-службы
- Затем я пытаюсь получить токен с помощью этой функции, используя azure.identity:
Код: Выделить всё
from azure.identity import ClientSecretCredential, AuthenticationRequiredError
def get_access_token(app_id, client_secret, directory_id):
try:
# Create the ClientSecretCredential using the provided credentials
credential = ClientSecretCredential(
client_id=app_id,
client_secret=client_secret,
tenant_id=directory_id
#scope="https://storage.azure.com/.default"
)
# Use the credential to get the access token
token = credential.get_token("https://storage.azure.com/.default").token
return token, credential
except AuthenticationRequiredError as e:
print("Authentication failed. Please check your credentials.")
raise e
except Exception as e:
print("An error occurred while getting the access token:")
print(str(e))
raise e
access_token, credential = get_access_token(app_id, client_secret, directory_id)
Код: Выделить всё
def check_connection_with_onelake(access_token):
base_url = "https://onelake.dfs.fabric.microsoft.com/9c3ffd43-b537-4ca2-b9ba-0c59d0094033/Files/sample?resource=file"
token_headers = {
"Authorization": "Bearer " + access_token
}
try:
response = requests.put(base_url, headers=token_headers)
if response.status_code == 200:
print("Connection with OneLake is successful.")
else:
print("Failed to connect with OneLake. Status code:", response.status_code)
except requests.exceptions.RequestException as e:
print("An error occurred while checking the connection:", str(e))
# Assuming 'access_token' is already defined and contains a valid access token
check_connection_with_onelake(access_token)

Где мне не хватает доступа и как мне предоставить правильный доступ?
ссылки:
https://learn.microsoft.com/en-us/ Fabric/onelake/onelake-access-api
https://amitchandak.medium.com/on-premi ... ouse-using -токен-d15b8795e349
Подробнее здесь: https://stackoverflow.com/questions/767 ... i-using-py