mandrewcito / signalrcore

SignalR Core python client
https://mandrewcito.github.io/signalrcore/
MIT License
115 stars 53 forks source link

Possibility to have custom query string argument #12

Closed morpheus65535 closed 4 years ago

morpheus65535 commented 5 years ago

Is your feature request related to a problem? Please describe. I'm trying to connect to a SignalR feed that require the use of an apikey parameters to be passed as a query string argument (?apikey=abc123...).

Describe the solution you'd like Would be great to have a qs attribute for the HubConnectionBuilder class.

Describe alternatives you've considered I've tried to append the apikey argument to my server_url but I get this error: Handshake status 400 Bad Request <class 'websocket._exceptions.WebSocketBadStatusException'>

Additional context Thanks for this great module!

mouzzampk2014-zz commented 5 years ago

Nice one morph

mandrewcito commented 5 years ago

Probably this weekend i'll work on this new feature. i'm thining about adding the parameter to the options in with_url method

hub_connection = HubConnectionBuilder()\ .with_url(server_url, options={ "access_token_factory": lambda: signalr_core_example_login(login_url, username, password), "querystring": "a=3&b=5" }).with_automatic_reconnect({ "type": "interval", "keep_alive_interval": 10, "intervals": [1, 3, 5, 6, 7, 87, 3] })\ .build()

what do you think about this way?

morpheus65535 commented 5 years ago

Should be perfectly fine to me! :-)

I've tried doing it by adding an attribute to the HubConnectionBuilder class but on_error is raised there: https://github.com/mandrewcito/signalrcore/blob/0351acf9f40eff3e452ec0de548e7063ea38d224/signalrcore/hub/base_hub_connection.py#L65

morpheus65535 commented 5 years ago

So, you had a nice weekend? ;-)

mandrewcito commented 5 years ago

yes, as soon i'll finish tests automation i merge the branch with changes. Only one test container left.

morpheus65535 commented 5 years ago

Ok let me know so I can test it with my signalR feed. Thank you!

mandrewcito commented 4 years ago

on version 0.7.7 you can add a querystring and library will manage it for you

connection = HubConnectionBuilder()\ .with_url("ws://localhost:83/hubs/chat?myid=234", options={ "access_token_factory": self.login })\ .configure_logging(logging.DEBUG)\ .with_automatic_reconnect({ "type": "raw", "keep_alive_interval": 10, "reconnect_interval": 5, "max_attempts": 5 }).build()

with this, 'myid=234' will be placed on hub connection url and negotiate url

morpheus65535 commented 4 years ago

Thanks!

This doesn't work in Python 2.x: https://github.com/mandrewcito/signalrcore/blob/c09bb83c5541081178ff38574acfa347938aaf61/signalrcore/hub/base_hub_connection.py#L56-L57

mandrewcito commented 4 years ago

Yes, i just released this fix on the following version(0.78) with the 'additional headers params' request. But Im thinking about stopping python2 support, because in 2020 python2 will not be maintained.

morpheus65535 commented 4 years ago

Yes I'm in the process of porting Bazarr to Python 3 also to be able to drop Python 2.7 support but in the mean time, I still have to be backward compatible... :-/

Thanks by the way!