TNTimmy
TNTimmy

Reputation: 21

Error using azure-eventhubs python example

I'm attempting to use the example code to receive data from Azure Event Hub.

Heres the code

import os
import sys
import logging
import time
from azure.eventhub import EventHubClient, Receiver, Offset

logger = logging.getLogger("azure")

ADDRESS = "amqps://mine.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=sadfsafdljksad=<eventhub>"

But I am getting the following error when executing..

Traceback (most recent call last):
  File "./recv.py", line 5, in <module>
    from azure.eventhub import EventHubClient, Receiver, Offset
ImportError: cannot import name 'EventHubClient'

Any assistance will be appreciated.

Upvotes: 1

Views: 3964

Answers (2)

Rodrigo Lopes
Rodrigo Lopes

Reputation: 1

Using this solution works fine reinstall the 1.3.3 version by using this command pip install azure-eventhub==1.3.3

Upvotes: 0

Ivan Glasenberg
Ivan Glasenberg

Reputation: 29940

I think you actually installed azure-eventhub package, version 5.0.0. But EventHubClient does not exist in 5.0.0 version, it exists in azure-eventhub package, version 1.3.3 or below.

By default, when you install the azure eventhub package for python using this command pip install azure-eventhub, it will automatically install the latest version 5.0.0. So this sentence from azure.eventhub import EventHubClient, Receiver, Offset will throw the error ImportError: cannot import name 'EventHubClient'

You can check the version of the package by open cmd -> input command pip show azure-eventhub. Screenshot as below:

enter image description here

There are 2 solutions:

Solution 1: keep using the 5.0.0 version, then you should re-write your code and follow the examples in this doc.

Solution 2: If you want to use the current code which includes from azure.eventhub import EventHubClient, Receiver, Offset, you should first uninstall the 5.0.0 version of azure-eventhub, then reinstall the 1.3.3 version by using this command pip install azure-eventhub==1.3.3

Upvotes: 2

Related Questions