I have a SignlaR server in ASP .NET Core 2.0 application hosted in Windows AZURE:
public class Chat : Hub { public Task Send(string message) { return Clients.All.InvokeAsync("Send", message); } }
I also have client in Javascript:
<script src="scripts/signalr-client.min.js"></script> connection.on('send', data => { console.log(data); }); connection.start() .then(() => connection.invoke('send', 'Hello'));
It works fine but how to connect this server in Python Script? There is the library: https://pypi.python.org/pypi/signalr-client/0.0.6
But doesn't work. I have an error:
signalr/negotiate 404 (not found)
Python code:
from requests import Session from signalr import Connection with Session() as session: #create a connection connection = Connection("wss://wg2.azurewebsites.net", session) #get chat hub chat = connection.register_hub("deviceshub") #start a connection connection.start()
Can you provide a working sample (Python client) with ASP .NET Core 2.0?
3 Answers
Answers 1
The python library you are using seems to be for the previous version of SignalR. SignalR for Asp.NET Core is not compatible with the previous version of SignalR so the old client will not work with the new server (or vice versa).
Answers 2
I have some suggestions which you can check:
Option 1
Stop using the SSL version and check if it works. Because at your Javascript function you use ws://" + window.location.host + "/chat
wss:// to ws://
Option 2
If I go to your domain wg2.azurewebsites.nl I get the following error:
Failed to load https://wg2.azurewebsites.net/deviceshub: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://wg2.azurewebsites.net' is therefore not allowed access. The response had HTTP status code 404.
Which means your server needs to respond a Access-Control-Allow-Origin
header with the domain name.
Option 3
In your javascript you connect to /chat
where now you try to connect to /deviceshub
maybe it does not exist. So change to chat
Answers 3
As you you are getting 404 error .
signalr/negotiate 404 (not found)
And in the python code,you are connecting to deviceshub
#get chat hub chat = connection.register_hub("deviceshub")
Shouldn't you be connecting to chathub ?
chat = connection.register_hub("chat")
If this does not help,double check the request send from python app.
If signalr connection gets successfull,you should see a url going like
double check the hostname and full url part if it is same as in the javascript client.
Hope this helps!
0 comments:
Post a Comment