Azure Event Hubs - REST API Authentication

荒凉一梦 提交于 2021-01-27 20:06:19

问题


I have a Python program that generates streaming data. Each piece of data is stored as a variable called message.

Since Event Hubs does not offer a Python SDK, I've opted to use their REST API. I've attempted to push the data to my Event Hub instance as a part of my Python program that generates data as follows:

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

print(r.status_code, r.reason)

Upon executing this code, I receive a 401 Unauthorized response.

After running into this issue, I used this tutorial to try and create a shared access signature. Upon using curl to confirm that my generated token worked, I received a HTTP/1.1 401 40103: Invalid authorization token signature response.

Is there a better way to send the data while still generating it in Python? A better way to create a shared access signature?


回答1:


Azure SDK for Python supports sending messages to Event Hubs: https://github.com/Azure/azure-sdk-for-python/tree/master/azure-servicebus#event-hub.

I'd suggest using the SDK but if you really want to call the REST API directly, take a look at the Event Hubs methods implementation in the SDK source: https://github.com/Azure/azure-sdk-for-python/blob/master/azure-servicebus/azure/servicebus/servicebusservice.py.



来源:https://stackoverflow.com/questions/44273427/azure-event-hubs-rest-api-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!