[Python] Cannot connect to Azure signalr from my python backend code

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

  1. Stack

    Stack Membro Participativo

    I want to send a message to my Azure SignalR using. I am using 'CommunicationIdentityClient' to get the acess token. But when I try to do


    identity = client.create_user()
    ​

    I am getting 403 error. How do I fix it?

    Here is my code

    from datetime import timedelta
    from azure.communication.identity import CommunicationIdentityClient

    connection_string = "Endpoint=https://signalrpro.service.signalr.net;AccessKey=acc;Version=1.0;"

    client = CommunicationIdentityClient.from_connection_string(connection_string)
    identity = client.create_user()
    print("\nCreated an identity with ID: " + identity.properties['id'])
    # Issue an access token with a validity of 24 hours and the "voip" scope for an identity
    # Issue an access token with a validity of an hour and the "voip" scope for an identity
    token_expires_in = timedelta(hours=1)
    token_result = client.get_token(identity, ["voip"], token_expires_in=token_expires_in)
    #token_result = client.get_token(identity, ["voip"])
    print("\nIssued an access token with 'voip' scope that expires at " + token_result.expires_on + ":")
    print(token_result.token)


    Edit: I looks like CommunicationIdentityClient is not a valid library for signalr. In that case how should I connect to SignalR?

    Continue reading...

Compartilhe esta Página