You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure AD守护程序应用使用Python调用Planner API时返回“The requested item is not found”错误的排查求助

Azure AD守护程序应用使用Python调用Planner API时返回“The requested item is not found”错误的排查求助

大家好,我遇到了一个棘手的问题,想请各位帮忙排查一下:

我开发了一个Azure AD守护程序应用,想要从指定的Planner中获取任务数据。我已经给这个应用分配了对应的应用权限,但调用Graph API获取计划信息时,一直返回**"The requested item is not found"**错误,我确认使用的Planner ID是正确的,现在不确定是缺少某个权限,还是代码里有问题。

我平时用VS Code运行Python文件,执行的命令是:python application.py parameters.json

我的Python代码如下:

import sys  # For simplicity, we'll read config file from 1st CLI param sys.argv[1]
import json
import logging

import requests
import msal


# Optional logging
# logging.basicConfig(level=logging.DEBUG)

config = json.load(open(sys.argv[1]))

# Create a preferably long-lived app instance which maintains a token cache.
app = msal.ConfidentialClientApplication(
    config["client_id"], authority=config["authority"],
    client_credential=config["secret"],
    # token_cache=...  # Default cache is in memory only.
                       # You can learn how to use SerializableTokenCache from
                       # https://msal-python.rtfd.io/en/latest/#msal.SerializableTokenCache
    )

# The pattern to acquire a token looks like this.
result = None

# Firstly, looks up a token from cache
# Since we are looking for token for the current app, NOT for an end user,
# notice we give account parameter as None.
result = app.acquire_token_silent(config["scope"], account=None)

if not result:
    logging.info("No suitable token exists in cache. Let's get a new one from AAD.")
    result = app.acquire_token_for_client(scopes=config["scope"])

if "access_token" in result:
    # Calling graph using the access token
    graph_data = requests.get(  # Use token to call downstream service
        config["endpoint"],
        headers={'Authorization': 'Bearer ' + result['access_token']}, ).json()
    print("Graph API call result: ")
    print(json.dumps(graph_data, indent=2))
else:
    print(result.get("error"))
    print(result.get("error_description"))
    print(result.get("correlation_id"))  # You may need this when reporting a bug

我使用的parameters.json配置文件:

{
  "authority": "https://login.microsoftonline.com/tenant_id",
  "client_id": "client_id",
  "scope": [ "https://graph.microsoft.com/.default" ],
  "secret": "Secret_Client",
  "endpoint": "https://graph.microsoft.com/v1.0/planner/plans/plan_id"
}

注:上面的ID都是占位符,实际运行时用的是真实的租户ID、客户端ID和计划ID。

当前分配给应用的权限:

已分配的应用权限

尝试了很多次都没解决,希望有经验的朋友能帮忙看看问题出在哪,多谢了!

备注:内容来源于stack exchange,提问作者Brian

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.13 19:38:08