Azure 事件中心 - REST API 身份验证

Azure Event Hubs - REST API Authentication

我有一个 Python 程序可以生成流数据。每条数据都存储为一个名为 message.

的变量

由于事件中心不提供 Python SDK,我选择使用 their REST API。我试图将数据推送到我的事件中心实例,作为我的 Python 程序的一部分,该程序生成数据如下:

r = requests.post("https://{Instance name}.servicebus.windows.net/{Path}/messages", message)

print(r.status_code, r.reason)

执行此代码后,我收到 401 Unauthorized 响应。

在 运行 进入这个问题后,我使用 this 教程尝试创建共享访问签名。在使用 curl 确认我生成的令牌有效后,我收到了 HTTP/1.1 401 40103: Invalid authorization token signature 响应。

有没有更好的方法来发送数据,同时仍然在 Python 中生成数据?创建共享访问签名的更好方法?

Python 的 Azure SDK 支持向事件中心发送消息:https://github.com/Azure/azure-sdk-for-python/tree/master/azure-servicebus#event-hub

我建议使用 SDK,但如果您真的想直接调用 REST API,请查看 SDK 源代码中的事件中心方法实现:https://github.com/Azure/azure-sdk-for-python/blob/master/azure-servicebus/azure/servicebus/servicebusservice.py.