Azure SignalR connection fails with 403 error in Python application

I’m trying to establish a connection to Azure SignalR service from my Python backend but running into issues. My goal is to send messages through the SignalR connection.

Currently I’m attempting to use the CommunicationIdentityClient library to obtain an access token, but when I execute the user creation method, I get a 403 forbidden error.

Here’s the code I’m working with:

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

connection_str = "Endpoint=https://myservice.service.signalr.net;AccessKey=mykey;Version=1.0;"

client_instance = CommunicationIdentityClient.from_connection_string(connection_str)
user_identity = client_instance.create_user()
print("\nUser created with ID: " + user_identity.properties['id'])

# Generate access token valid for 1 hour with voip scope
token_duration = timedelta(hours=1)
token_response = client_instance.get_token(user_identity, ["voip"], token_expires_in=token_duration)
print("\nGenerated token with 'voip' scope expires at " + token_response.expires_on + ":")
print(token_response.token)

I’m starting to suspect that CommunicationIdentityClient might not be the correct library for SignalR connections. What’s the proper way to authenticate and connect to Azure SignalR from Python? Any guidance would be appreciated.

Wait, are you sending messages TO clients or getting them FROM a Python backend? That changes everything. If you’re just pushing server-side messages, REST API is way easier. What’s your actual use case tho? Chat app or something else?

You’re right - CommunicationIdentityClient won’t work for Azure SignalR. That’s for Azure Communication Services, which is completely different. For SignalR, use the azure-signalr Python SDK or hit the REST API directly. Authentication works differently too - SignalR uses connection strings and access keys, not user identity tokens. You’ll need SignalR client libraries that support the SignalR protocol, or build server-side functionality with the SignalR REST API for sending messages. Your connection string format looks good, just use it with the actual SignalR libraries instead of the Communication Services SDK.

yeah, that’s the wrong sdk entirely lol. communication services isn’t signalr service. for python signalr connections, try the signalrcore package or just hit the rest api endpoints directly. your connection string works fine with the requests library - just use /api/v1/hubs/{hub}/users/{user} to send messages. way simpler than messing with user tokens.