Python MS Graph API在每次运行时返回不同的值

Python MS Graph API在每次运行时返回不同的值,python,flask,microsoft-graph-api,Python,Flask,Microsoft Graph Api,我正在使用Flask应用程序从MS Graph API收集数据并更新MS团队。我正在使用微软的Python模板应用程序来实现这一点。当我调用API GET来获取团队的通道列表时,它会返回不稳定的值。大多数情况下,返回值中缺少一些通道,而MS团队显示该通道存在。在更新或添加通道后的第一次调用之后,经过几次GET调用之后,这种情况会得到改善,但仍然不一致。MS API在定期GET调用中返回不一致结果的原因是什么?我是否需要在这些通话之间实施暂停/中断? 我感谢你的帮助 @app.route(&quo

我正在使用Flask应用程序从MS Graph API收集数据并更新MS团队。我正在使用微软的Python模板应用程序来实现这一点。当我调用API GET来获取团队的通道列表时,它会返回不稳定的值。大多数情况下,返回值中缺少一些通道,而MS团队显示该通道存在。在更新或添加通道后的第一次调用之后,经过几次GET调用之后,这种情况会得到改善,但仍然不一致。MS API在定期GET调用中返回不一致结果的原因是什么?我是否需要在这些通话之间实施暂停/中断? 我感谢你的帮助

@app.route("/graphcall")
def graphcall():
    token = _get_token_from_cache(app_config.SCOPE)
    if not token:
        return redirect(url_for("login"))
    headers = {'Authorization': 'Bearer ' + token['access_token']}
    teamInfo = teamInfo_func()
    
    graph_data = requests.get(
        app_config.ENDPOINT + '/users/?$filter=userType eq \'guest\'',
        headers=headers,
        )
    ## some work on graph_data

    graph_data = requests.get(
        app_config.ENDPOINT + '/teams/%s/members'%teamInfo[1],
        headers=headers,
        )
    ## some work on graph_data
    
    graph_data = requests.get(
        app_config.ENDPOINT + '/teams/%s/channels'%teamInfo[1],
        headers=headers,
        )
    ## some work on graph_data
    
    teams_data = graph_data.json()
    for channel in teams_data['value']:
        graph_data = requests.get(
            app_config.ENDPOINT + '/teams/%s/channels/%s/members'%(teamInfo[1], channel['id']),
            headers=headers,
            )        
        ## some work on graph_data
        
    try:
        # to Add
        for i in toAdd_df['...'].unique():
            toAdd_temp_df = toAdd_df[toAdd_df['...']==i].reset_index(drop=True)            
            if toAdd_temp_df.loc[0, '...']==1:
                name = ...
                email = ...
                url = app_config.ENDPOINT + '/invitations'
                invite_obj = {
                    "invitedUserDisplayName": "%s"%name,
                    "invitedUserEmailAddress": email,
                    "sendInvitationMessage": False,
                    "inviteRedirectUrl": "..."
                }
                result = requests.post(url, json = invite_obj, headers = headers)
                if result.status_code==201:
                    user_ID = ...
                    url = app_config.ENDPOINT + '/teams/%s/members'%teamInfo[1]
                    add_obj = {
                        "@odata.type": "#microsoft.graph.aadUserConversationMember",
                        "roles": ["Guest"],
                        "user@odata.bind": "https://graph.microsoft.com/v1.0/users('%s')"%user_ID
                    }
                    result = requests.post(url, json = add_obj, headers = headers)
                    if result.status_code==201:
                        for j in toAdd_temp_df['...'].values:
                            channel_ID = ...
                            url = app_config.ENDPOINT + '/teams/%s/channels/%s/members'%(teamInfo[1], channel_ID)
                            add_obj = {
                                "@odata.type": "#microsoft.graph.aadUserConversationMember",
                                "roles": ["Guest"],
                                "user@odata.bind": "https://graph.microsoft.com/v1.0/users('%s')"%user_ID
                            }
                            result = requests.post(url, json = add_obj, headers = headers).
                            if result.status_code==201:
                                ...
            else:
                user_ID = ...
                for j in toAdd_temp_df['...'].values:
                    if j not in df_teams['...'].values:
                        url = app_config.ENDPOINT + '/teams/%s/channels'%teamInfo[1]
                        channel_obj = {
                            "displayName": j,
                            "description": "...",
                            "membershipType": "private"
                        }
                        result = requests.post(url, json = channel_obj,headers = headers)
                        if result.status_code==201:                      
                            channel_ID = ...
                            url = app_config.ENDPOINT + '/teams/%s/channels/%s/members'%(teamInfo[1], channel_ID)
                            add_obj = {
                                "@odata.type": "#microsoft.graph.aadUserConversationMember",
                                "roles": ["Guest"],
                                "user@odata.bind": "https://graph.microsoft.com/v1.0/users('%s')"%user_ID
                            }
                            result = requests.post(url, json = add_obj, headers = headers)
                            if result.status_code==201:
                                ...
                            else:
                                print(result.json())
                        else:
                            print(result.json())
                    else:
                        channel_ID = ...          
                        url = app_config.ENDPOINT + '/teams/%s/channels/%s/members'%(teamInfo[1], channel_ID)
                        add_obj = {
                            "@odata.type": "#microsoft.graph.aadUserConversationMember",
                            "roles": ["Guest"],
                            "user@odata.bind": "https://graph.microsoft.com/v1.0/users('%s')"%user_ID
                        }
                        result = requests.post(url, json = add_obj, headers = headers)
                        if result.status_code==201:
                            ...
                        else:
                            print(result.json())
        
        # to Rem/Del
        toRem_df = df_channels[df_channels['...']==1].reset_index(drop=True)  
        for i in toRem_df['...'].unique():
            toRem_temp_df = toRem_df[toRem_df['...']==i].reset_index(drop=True)
            if toRem_temp_df.loc[0, '...']==1:
                membership_ID = df_teams_members[df_teams_members['...']==i]['...'].item()
                url = app_config.ENDPOINT + '/teams/%s/members/%s'%(teamInfo[1], membership_ID)
                result = requests.delete(url, headers=headers)
                if result.status_code==204:
                    ...
                else:
                    print(result.json())
            else:
                for j in toRem_temp_df['...'].values:
                    temp_temp = toRem_temp_df[toRem_temp_df['...']==j]
                    channel_ID = temp_temp.loc[0, '...']
                    membership_ID = temp_temp.loc[0, '...']
                    url = app_config.ENDPOINT + '/teams/%s/channels/%s/members/%s'%(teamInfo[1], channel_ID, membership_ID)
                    result = requests.delete(url, headers=headers)
                    if result.status_code==204:
                        ...
                    else:
                        print(result.json())
    
    except Exception as e:
        ...