我有一个生成流数据的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
确认生成的 token 有效后,我收到了 HTTP/1.1 401 40103:无效的授权 token 签名
响应。
有没有更好的方法来发送数据,同时仍然用 Python 生成数据?创建共享访问签名的更好方法?
最佳答案
Azure SDK for Python 支持向事件中心发送消息: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 .
关于Azure 事件中心 - REST API 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44273427/