I have 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 library: https://pypi.python.org/pypi/signalr-client/0.0.6
But doesn't work. I have 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 working sample (Python client) with ASP .NET Core 2.0?
1 Answers
Answers 1
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
0 comments:
Post a Comment