【问题标题】:Status Code: 0 Microsoft.Graph.ServiceException: Code: tooManyRetries Message: More than 3 retries encountered while sending the request状态代码:0 Microsoft.Graph.ServiceException:代码:tooManyRetries 消息:发送请求时遇到超过 3 次重试
【发布时间】:2021-04-22 18:58:58
【问题描述】:

当我们尝试使用 Graph API 从日历中获取会议时,我们遇到了异常

获取日历事件的代码:

GraphServiceClient service = new GraphServiceClient(
                new DelegateAuthenticationProvider(
                    async (request) =>
                    {
                        request.Headers.Authorization =
                            new AuthenticationHeaderValue("Bearer", accessToken);
                        await Task.FromResult<string>(null);
                    }));


eventResult = await service.Users[connectedAccountEmailID].Calendars[calendarId].CalendarView.Request(options)
                        .Select("id,subject,organizer,start,end,attendees,showas,isallday,seriesmasterid")
                        .Header("Prefer", "IdType=\"ImmutableId\"")
                        .GetAsync();

我们得到的异常是

exeptionType : System.AggregateException

Status Code: 0
Microsoft.Graph.ServiceException: Code: tooManyRetries
Message: More than 3 retries encountered while sending the request.

   at Microsoft.Graph.HttpProvider.<SendRequestAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Graph.HttpProvider.<SendAsync>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Graph.BaseRequest.<SendRequestAsync>d__38.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Graph.BaseRequest.<SendAsync>d__34`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Graph.CalendarCalendarViewCollectionRequest.<GetAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Service.Office365CalendarProviderService.<>c__DisplayClass44_0.<<GetCalendarMeetings>b__0>d.MoveNext()

我检查了代码并确认我们没有同时进行任何并行调用,但仍然遇到限制类型的异常。

任何帮助将不胜感激

【问题讨论】:

  • 对 Azure 没有任何内幕,但我注意到状态码是 0。即使图 API 服务器没有发送 HTTP 码 429 来指定过多的请求,它也会 (可能)仍然发送 0 以外的内容。因此,除非您使用的库解析响应不正确,否则 A.)您的请求永远不会到达服务器或 B.)服务器会立即关闭连接。如果您有能力这样做,您可以尝试在请求期间运行wireshark,或者通过调试器单步执行以查看库在哪个阶段停止。

标签: microsoft-graph-api azure-ad-graph-api office365api


【解决方案1】:

此错误表明 .NET SDK 的内置重试处理程序已重试失败请求的最大次数(请参阅https://github.com/microsoftgraph/msgraph-sdk-dotnet-core/blob/2466fdca28d807b727497db7dc8c7767d513f62f/src/Microsoft.Graph.Core/Requests/Middleware/RetryHandler.cs#L132-L137)。三倍是默认的最大重试值。

重试只发生在特定的 HTTP 状态代码(429、503 或 504)中,因此出于某种原因,您在应用中遇到了这种情况。您可能会尝试的一件事是尝试使用 Graph Explorer 对同一用户进行相同的 API 调用。查看 AggregateException 上的其余字段以了解“真正的”异常是什么也可能会有所帮助。网络捕获也可能会暴露更多的调试信息。

如果所有这些都不能提供答案,您可能需要联系support

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2023-03-06
  • 2021-06-16
  • 2017-11-17
  • 1970-01-01
  • 1970-01-01
  • 2012-08-10
  • 2019-11-25
  • 2021-06-04
相关资源
最近更新 更多