Azure / Azure/azure-sdk-for-python

EventHubConsumerClient requiring "http://" prepended to hostname in proxy configuration

Open
#40,274 3 comments 1 reaction 1 assignee Claimed by @kashifkhan View on GitHub
Client customer-reported Event Hubs feature-request Messaging needs-team-attention question
Dominant language
Python
Stars
5.6k
Forks
3.4k
Avg merge
1d 21h
Merged PRs (30d)
193

Description

- **Package Name**: azure-eventhub
- **Package Version**: 5.14.0
- **Operating System**: Ubuntu
- **Python Version**: Python 3.10.12 (main, Feb 4 2025, 14:57:36)

**Describe the bug**
EventHubConsumerClient takes an argument `http_proxy` which behaves differently in the synchronous versus the asynchronous:

synchronous:
```
from azure.eventhub import EventHubConsumerClient
...
http_proxy = {
"proxy_hostname": "127.0.0.1",
"proxy_port": 3128,
}
```
asynchronous:
```
from azure.eventhub.aio import EventHubConsumerClient
...
http_proxy = {
"proxy_hostname": "http://127.0.0.1",
"proxy_port": 3128,
}
```
I consider this as a bug

**To Reproduce**
Omitting the https:// before the hostname in asynch case
```
import asyncio
import os

from aiohttp import ClientSession
from azure.eventhub import TransportType, EventData
from azure.eventhub.aio import EventHubConsumerClient
...
http_proxy = {
"proxy_hostname": "127.0.0.1",
"proxy_port": 3128,
}
async def on_event(partition_context, event: EventData):
print("Received event: ", event.body_as_str())
await partition_context.update_checkpoint(event)

async def main():
async with ClientSession() as session:
client = EventHubConsumerClient.from_connection_string(
conn_str=eventhub_connection_string,
consumer_group="$Default",
transport_type=TransportType.AmqpOverWebsocket,
http_proxy=http_proxy,
)

try:
async with client:
await client.receive(
on_event=on_event,
starting_position="-1", # "-1" is from the beginning of the partition.
)
except KeyboardInterrupt:
print("received keyboard interrupt")
finally:
await client.close()

if __name__ == "__main__":
asyncio.run(main())
```
will produce

```
Unclosed client session
client_session:
Unclosed client session
client_session:
Unclosed client session
client_session:
...
EventProcessor instance '88bfc0be-39eb-4199-9fe1-84a781f0855c' of eventhub 'graphevents' consumer group '$Default'. An error occurred while load-balancing and claiming ownership. The exception is EventHubError('127.0.0.1:3128\n127.0.0.1:3128'). Retrying after 32.00170602902956 seconds
```
I even think there might be an issue with the handling of this error as the client sessions is not properly closed.

**Expected behavior**
Code reads events from the hub.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.