Доступ к API AzurePython

Программы на Python
Anonymous
Доступ к API Azure

Сообщение Anonymous »

Я хочу иметь доступ к API этого файла Swagger: https://flightclaims-dev.azurewebsites. ... index.html
Но при использовании следующего кода я столкнулся с ошибкой 401: p>
`

Код: Выделить всё

from azure.identity import ClientSecretCredential
import requests

# Azure AD configuration
TENANT_ID = 'xxx'
CLIENT_ID = 'xxx'
CLIENT_SECRET = 'xxx'

# Delegated scopes required for Microsoft Graph API access
SCOPES = ['User.Read']  # Example scopes

# Initialize the Azure Identity client with client secret credential
credential = ClientSecretCredential(
tenant_id=TENANT_ID,
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET
)

# Obtain an access token for Microsoft Graph API with delegated permissions
token_data = credential.get_token("https://graph.microsoft.com/.default", scopes=SCOPES)
access_token = token_data.token
print(token_data)
# Microsoft Graph API endpoint
graph_api_endpoint = 'https://flightclaims-dev.azurewebsites.net/api/ApplicationParameter'

# Set headers with Authorization token
headers = {
'Authorization': 'Bearer ' + access_token
}

try:
# Make a GET request to Microsoft Graph API endpoint with headers
response = requests.get(graph_api_endpoint, headers=headers)

# Check if the request was successful (status code 200)
if response.status_code == 200:
# Print the response data
print(response.json())
else:
# Print error message if request was not successful
print(f'\nFailed to retrieve data. Status code: {response.status_code}')
print(response.text)  # Print error response if needed

except requests.exceptions.RequestException as e:
# Print error message if an exception occurs during the request
print(f'An error occurred: {e}')
`
Кстати, токен, который я получаю, правильный
Мне, вероятно, нужно изменить свой Разрешения API Azure, но я не знаю как?

Подробнее здесь: https://stackoverflow.com/questions/784 ... api-access

Вернуться в «Python»