[Python] Cannot connect to azure pubsub group from my streamlit app

Discussão em 'Python' iniciado por Stack, Abril 13, 2025.

  1. Stack

    Stack Membro Participativo

    I have a streamlit with connect button. On clicking the connect button it should create a connection to azure pubsub. But I am getting the following error. SendMessageError: Failed to send message. The streamlit code is

    import azure.messaging.webpubsubclient
    import streamlit
    from azure.messaging.webpubsubclient import WebPubSubClient
    from azure.messaging.webpubsubclient.models import CallbackType, WebPubSubDataType
    if streamlit.button("Connect"):
    client = WebPubSubClient("wss://blablabla.webpubsub.azure.com/client/hubs/Hub?access_token=access")
    with client:
    # The client can join/leave groups, send/receive messages to and from those groups all in real-time
    group_name = "group1"
    client.subscribe(CallbackType.GROUP_MESSAGE, lambda e: print(f"Received message: {e.data}"))
    # ...continues the code snippet from above
    client.is_connected()
    client.join_group(group_name)
    # Send a message to a joined group
    client.send_to_group(group_name, "hello world", WebPubSubDataType.TEXT)

    # In the Console tab of your developer tools found in your browser, you should see the message printed there.
    # A client needs to join the group it wishes to receive messages from
    # client.join_group(group_name)


    In the azure portal I also dont see any hub or group. Do I need to change anything in the portal? How to fix it.

    I was expecting to connect to azure pub sub server, but it is not working

    Continue reading...

Compartilhe esta Página