Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
MarcoFogale
Frequent Visitor

Eventstream Failed to initiate the connection due to exception: [WinError 121] The semaphore timeout

I am trying to use a Python script to load data to an Eventstream on Microsoft Fabric, inspired by this article:

https://support.fabric.microsoft.com/de-ch/blog/microsoft-fabric-event-streams-generating-real-time-...

 

My scenario is slightly different: instead of getting the data from an API, I am getting temperature data from an Arduino device, connected to an on-premise Windows Server 2022.

The data come from the device correctly, and I transform it into a JSON that I would like to send to the eventstream thanks to a python script running on my server.

Python and all the packages are correctly installed, and I have admin privileges on the workspace.

 

This is the Python code that I am trying to use:

async def run():
    # Create a producer client to send messages to the EventStream.
    # Specify a connection string to your EventStream namespace and the eventstream name.
    producer = EventHubProducerClient.from_connection_string(
        conn_str=EVENTSTREAM_CONNECTION_STR,
        eventhub_name=EVENTSTREAM_NAME
    )
    async with producer:
        while True:
            # get the temperature data in Json format
            json_data = get_temperature()
            # Create a batch.
            event_data_batch = await producer.create_batch()
            event_data_batch.add(EventData(json_data))
            # Send the batch of events to the event hub.
            await producer.send_batch(event_data_batch)
            # Wait for 6 minutes before generating the next point
asyncio.run(run())

 

The code run correctly until the "await producer.create_batch() " row, which generate the following error:

azure.eventhub.exceptions.ConnectError: Failed to initiate the connection due to exception: [WinError 121] The semaphore timeout period has expired

 

I imagine that it is a network issue, but I can't figure out how to solve it.

The firewall has a rule that allow port 443 oubound connections.

 

What am I missing?

 

Thank you a lot

 

Marco Fogale

1 REPLY 1
v-tangjie-msft
Community Support
Community Support

Hi @MarcoFogale ,

 

Please take the following steps to troubleshoot the problem:

1. Verify Connection String and Event Hub Name, ensure that the and you are using in your script are correct. 

2. Since the error message indicates a timeout, it's possible that network latency or connectivity issues between your Windows Server and the Azure Event Hub are causing the timeout. You can use tools like or to check the connectivity and latency to the Azure Event Hub endpoint.

3. Although the Azure Event Hub SDK may not directly expose a timeout setting, you can try adjusting the underlying network settings or use a retry policy with a longer timeout. Refer to the Azure Event Hubs retry policy documentation for guidance on implementing a custom retry policy.

4. Ensure that there are no additional firewalls, VPNs, or network security groups that might be interfering with the connection to Azure Event Hubs.

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors