python - Azure Functions (python) adal 身份验证超时

标签 python python-3.x azure azure-functions

我正在尝试使用 Python 的 Azure Functions(Linux 应用服务计划)。我已经编写了一个基本代码,可以使用 Azure 验证我的函数。它通过 ADAL 身份验证使用服务主体详细信息(在 AppSettings 中设置)。我已通过 Visual Studio Code 部署了该函数。当我运行该函数时,它会永远运行,并给出“503”错误。

正如您所看到的,代码非常简单,它只是进行身份验证。我想知道为什么它运行了 5 分钟以及如何修复它。我是否遗漏了导致此问题的任何内容。

代码:

import logging
import os, adal
import azure.functions as func
from azure.mgmt.resource import SubscriptionClient
from msrestazure.azure_active_directory import AdalAuthentication
from msrestazure.azure_cloud import AZURE_PUBLIC_CLOUD


def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    
    # Retrieve the IDs and secret to use with ServicePrincipalCredentials 
    logging.info('Logging environment Variables...')
    client_id = os.environ["AZURE_CLIENT_ID"]
    client_secret = os.environ["AZURE_CLIENT_SECRET"]
    client_subscription_id = os.environ["AZURE_SUBSCRIPTION_ID"]
    client_tenant_id = os.environ["AZURE_TENANT_ID"]
    
    LOGIN_ENDPOINT = AZURE_PUBLIC_CLOUD.endpoints.active_directory
    logging.info(f'login endoint: {LOGIN_ENDPOINT}')
    
    RESOURCE = AZURE_PUBLIC_CLOUD.endpoints.active_directory_resource_id
    logging.info(f'resource: {RESOURCE}')
    
    context = adal.AuthenticationContext(LOGIN_ENDPOINT + '/' + client_tenant_id)
    
    credential = AdalAuthentication(context.acquire_token_with_client_credentials, RESOURCE, client_id, client_secret)
    subscription_client = SubscriptionClient(credential)
    
    subscription = next(subscription_client.subscriptions.list())
    logging.info(f'Client ID: {client_id}, Client Subscription ID: {subscription}')
    
    #return func.HttpResponse(f'Client ID: {client_id}, Client Subscription ID: {subscription}')
    return func.HttpResponse(f'Client ID: {client_id}')

错误:

Timeout value of 00:30:00 exceeded by function 'Functions.StorageAccountDeployer' (Id: '2ecd0e1e-ef17-44fc-a1d7-d0134b9f9e3e'). Initiating cancellation.

最佳答案

查看 Azure AD 是否已授予服务主体检索 token 的权限。

关于python - Azure Functions (python) adal 身份验证超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63009238/

相关文章:

python - 写入打开的 CSV 时跳过 header

python - 限制并行工作的线程数

azure - 使用 Azure CLI (2.0.23) 创建函数应用程序无法链接到部署源 url

python - 暂停/恢复脚本执行?

python - 设置标志使项目不可选择,稍后再次可选择

mysql - 当在 python 中插入多个数据帧时,没有从 mysql 获取值

Python 版本和 sublime 构建

python - pyQt : How do I update a label?

email - 我应该使用 GRAPH API 还是简单的 SMTP 类来创建电子邮件?

Azure Pipeline 在触发器路径中使用星号包括