azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

Send an event to Azure Event Hub authenticating via Service Principal throws "azure.eventhub.exceptions.EventHubError: get_token must be a coroutine function" error

Open rbuenoc opened this issue 4 years ago • 0 comments

  • Package Name: azure-eventhub
  • Package Version: 5.10.1
  • Operating System: Windows
  • Python Version: 3.9.4

Describe the bug Trying to send an event to Azure Event Hub authenticating via Service Principal throws "azure.eventhub.exceptions.EventHubError: get_token must be a coroutine function" error

To Reproduce Steps to reproduce the behavior:

  1. Install requirements
azure-identity==1.10.0
azure-eventhub==5.10.1
  1. Run the following code, replacing the corresponding variables.
import asyncio
from azure.identity import ClientSecretCredential
from azure.eventhub.aio import EventHubProducerClient
from azure.eventhub import EventData

async def run():
    credentials = ClientSecretCredential('<tenant-id>', '<application-id>', '<secret-key>')
    producer = EventHubProducerClient('<fully-qualified-namespace>', '<eventhub-name>', credentials)
    async with producer:
        event_data_batch = await producer.create_batch()
        event_data_batch.add(EventData('First event '))
        event_data_batch.add(EventData('Second event'))
        event_data_batch.add(EventData('Third event'))

        await producer.send_batch(event_data_batch)

loop = asyncio.get_event_loop()
loop.run_until_complete(run())

Expected behavior Code running successfully and message sent to Azure Event Hub without any error.

rbuenoc avatar Aug 25 '22 17:08 rbuenoc