Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Error when connecting to Asp.net SignalR #10

Open
ngunhaSO opened this issue Sep 12, 2018 · 6 comments
Open

Error when connecting to Asp.net SignalR #10

ngunhaSO opened this issue Sep 12, 2018 · 6 comments

Comments

@ngunhaSO
Copy link

I am trying your library with python 3.6.5
However, when I try to connect to my vendor signalr endpoint, I got the following error:

File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/signalr_aio/_connection.py", line 36, in start
self.__transport.start()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/signalr_aio/transports/_transport.py", line 47, in start
self.ws_loop.run_until_complete(self.socket(self.ws_loop))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 468, in run_until_complete
return future.result()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/signalr_aio/transports/_transport.py", line 59, in socket
loop=loop) as self.ws:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/websockets/py35/client.py", line 2, in aenter
return await self
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/websockets/py35/client.py", line 19, in await_impl
extra_headers=protocol.extra_headers,
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/websockets/client.py", line 263, in handshake
raise InvalidStatusCode(status_code)
websockets.exceptions.InvalidStatusCode: Status code not 101: 400

Can you help me with this issue?

I have tried with this library https://github.com/TargetProcess/signalr-client-py and it is able to connect sucessfully. However, the project doesn't seem active recently, so i wanna try different available packages.

@slazarov
Copy link
Owner

Can you post your code or snippet so I could replicate it?

@ngunhaSO
Copy link
Author

ngunhaSO commented Sep 13, 2018

I used your example code, and replace it with our vendor signalr endpoint. I also pass in session object into the connection.

from signalr_aio import Connection
from base64 import b64decode
from zlib import decompress, MAX_WBITS
import json
from requests import Session

async def process_message(message):
    deflated_msg = decompress(b64decode(message), -MAX_WBITS)
    return json.loads(deflated_msg.decode())
async def on_debug(**msg):
    if 'R' in msg and type(msg['R']) is not bool:
        decoded_msg = await process_message(msg['R'])
        print(decoded_msg)
async def on_error(msg):
    print(msg)
async def on_message(msg):
    decoded_msg = await process_message(msg[0])
    print(decoded_msg)

def print_all_active_devices(data):
    print('\n Active devices: ', data)

if __name__ == "__main__":
    with Session() as session:
        connection = Connection('<signalR_endpoint>', session)
        hub = connection.register_hub('<hub_name>')

        hub.client.on('getAllActiveDevices', print_all_active_devices)
        hub.server.invoke('getAllActiveDevices')
        connection.start()

@ngunhaSO
Copy link
Author

Also, please note that if i use your example signalr endpoint, it works. I believe our vendor use asp.net signalr, not the asp.net core signalr.

@slazarov
Copy link
Owner

It's related to the session you are passing, you are getting
400 Bad Response
https://httpstatuses.com/400

File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/websockets/client.py", line 263, in handshake
raise InvalidStatusCode(status_code)
websockets.exceptions.InvalidStatusCode: Status code not 101: 400

Is the endpoint cloudflare protected?

What happens if you dont pass a session object, i.e

connection = Connection('<signalR_endpoint>', session=None)

Also correct you method definition to:

async def print_all_active_devices(data):
    print('\n Active devices: ', data)

@ngunhaSO
Copy link
Author

I have changed the print_all_active_devices method, and removed the session from the Connection but I still get the same error. The signal endpoint at the moment is still http not https as your example. Does it need to be https?

@TiBarification
Copy link

I have the same problem, status code 400, only http provided.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants