简体   繁体   English

事件中心错误:放置令牌失败。 状态码:401,状态描述:ExpiredToken

[英]Event Hub Error: Put token failed. status-code: 401, status-description: ExpiredToken

I am working on program in which sending messages from C# console application to Azure Event Hub.我正在开发将消息从 C# 控制台应用程序发送到 Azure 事件中心的程序。 Code reference link as follows:代码参考链接如下:

Ref Link: https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-dotnet-standard-getstarted-send参考链接: https ://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-dotnet-standard-getstarted-send

In this above code i am getting exception as: Put token failed.在上面的代码中,我收到异常:Put token failed。 Status Code: 401 : Expired Token.状态码:401:过期令牌。 I have tried to regenerate primary and secondary key.我试图重新生成主键和辅助键。 Below is the format of connection string and entity path values as follows:下面是连接字符串和实体路径值的格式如下:

在此处输入图像描述

Please provide solution for it.请提供解决方案。 Thank You.谢谢你。

I hope it is not too late!我希望还为时不晚!

I had the same issue and my problem was, that I have changed the system time from the device, that connects to the event hub.我有同样的问题,我的问题是,我已经从连接到事件中心的设备更改了系统时间。 I have set it from 7 o'clock to 4 o'clock.我把它从 7 点到 4 点。

The following may be a very specific scenario.以下可能是一个非常具体的场景。

If you are facing this issue running your app with Docker in Windows and Docker is running via WSL 2 (instead of HyperV), there is a WSL 2 issue that still needs to be addressed by Microsoft:如果您在 Windows 中使用 Docker 运行应用程序时遇到此问题,并且 Docker 通过 WSL 2(而不是 HyperV)运行,则 Microsoft 仍需要解决 WSL 2 问题:

It is a time synchronization issue between the host OS and the running containers.这是主机操作系统和正在运行的容器之间的时间同步问题。 They basically have a different date/time and that creates trouble when authenticating via tokens that expire.它们基本上具有不同的日期/时间,并且在通过过期令牌进行身份验证时会产生麻烦。

This happened when my laptop woke up after sleep/hibernation.这发生在我的笔记本电脑在睡眠/休眠后醒来时。 I run my app using Docker containers.我使用 Docker 容器运行我的应用程序。 When it tries to connect to Service Bus I start to get those unauthorized errors, but only after sleep mode, not before.当它尝试连接到服务总线时,我开始收到那些未经授权的错误,但只是在睡眠模式之后,而不是之前。

Some said it got solved by restarting the docker host.有人说它通过重新启动docker主机解决了。 In my case it only worked restarting my PC.就我而言,它只能重新启动我的电脑。 After a while I found:过了一会儿,我发现:

https://github.com/microsoft/WSL/issues/4245 https://github.com/microsoft/WSL/issues/4245

Now I don't need to reboot Windows anymore, just running现在我不再需要重新启动 Windows,只需运行

wsl --shutdown

Fixes the issue forcing a time sync between OS/containers (it will also cause a docker host restart).修复了在操作系统/容器之间强制时间同步的问题(它也会导致 docker 主机重启)。

I just had the same when running inside docker for windows.在 docker for windows 中运行时,我也遇到了同样的情况。 I restarted the docker host and it worked - no clue why我重新启动了 docker 主机并且它工作了 - 不知道为什么

For me the issue "Put token failed. status-code: 401, status-description: Unauthorized" was caused by the networking configuration of the storage account where Azure EventHub client persists checkpoints.对我来说,问题“放置令牌失败。状态代码:401,状态描述:未授权”是由 Azure EventHub 客户端保留检查点的存储帐户的网络配置引起的。 Both the SA and EH have had whitelisted client address, and it works when I run client app from my laptop (behind the proxy btw). SA 和 EH 都已将客户端地址列入白名单,当我从笔记本电脑运行客户端应用程序时(顺便说一句,在代理后面),它就可以工作。 But when the same client deployed to AKS and acting through AKS egress public IP, even this IP whitelisted on the SA and EH, the EH accepts incoming connection, but the SA decline it.但是,当同一客户端部署到 AKS 并通过 AKS 出口公共 IP 执行操作时,即使此 IP 在 SA 和 EH 上列入白名单,EH 也会接受传入连接,但 SA 拒绝它。 I am not sure where the AKS pod inciating connection from_ no any logged connection attempts on the SA.我不确定 AKS pod 发起连接的来源_SA 上没有任何记录的连接尝试。 When I made SA accept connections from "All networks", the issue "Put token failed. status-code: 401, status-description: Unauthorized" has gone.当我让 SA 接受来自“所有网络”的连接时,问题“放置令牌失败。状态代码:401,状态描述:未授权”已经消失。 Microsoft reccomended to deploy SA into another region to have EH and SA in different regions, but I didn´t test it yet, and due to billed traffic I wouldn´t. Microsoft 建议将 SA 部署到另一个区域,以便在不同区域拥有 EH 和 SA,但我还没有测试它,并且由于计费流量我不会。 Hope this help.希望这有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 消息未发送到 Azure 事件中心:放置令牌失败。 状态代码:404,状态描述:消息实体... ...找不到 - Message not sending to Azure Events Hub: Put token failed. status-code: 404, status-description: The messaging entity... ...could not be found Azure SDK UnauthorizedException:放置令牌失败。 状态码:401,状态描述:未授权:当 KeyName 为空时,资源 URI 必须 - Azure SDK UnauthorizedException: Put token failed. status-code: 401, status description: Unauthorized: When KeyName is empty the resource URI must 刷新访问令牌失败,状态码为:401 - Refresh access token failed with status code: 401 在webapi中设置状态代码和内容 - Set status-code and content in webapi 错误请求失败,HTTP状态为401:未经授权 - Error The request failed with HTTP status 401: Unauthorized 如何在Windows Server 2012R2上的机器人中射击“刷新访问令牌失败,状态代码:401” - How to trouble shoot “Refresh access token failed with status code: 401 ” in bot on Windows Server 2012R2 请求失败,HTTP状态为401:未经授权 - The request failed with HTTP status 401: Unauthorized 来自请求标头的Web异常返回状态代码描述,但不返回错误 - Web Exception from requesting headers is returning the status code description but not the error 请求失败,HTTP状态为401:未授权。 - The request failed with HTTP status 401: Unauthorized. 请求失败,HTTP 状态为 401:未授权 IN SSRS - The request failed with HTTP status 401: Unauthorized IN SSRS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM