2
votes

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

1 Answers

2
votes

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.