richard-better / pushbullet.py

A python client for http://pushbullet.com
MIT License
575 stars 110 forks source link

WebSocket Functions Missing Argument #173

Closed xifer closed 3 years ago

xifer commented 3 years ago

I got these errors with DEBUG turned on (and push messages were not being received properly):

ERROR:websocket:error from callback <bound method Listener.on_open of <Listener(Thread-1, initial)>>: on_open() takes 1 positional argument but 2 were given File "/usr/lib/python3.9/site-packages/websocket/_app.py", line 388, in _callback callback(self, args) ERROR:websocket:error from callback <bound method Listener.on_message of <Listener(Thread-1, initial)>>: on_message() takes 2 positional arguments but 3 were given File "/usr/lib/python3.9/site-packages/websocket/_app.py", line 388, in _callback callback(self, args) ^C^CERROR:websocket:error from callback <bound method Listener.on_close of <Listener(Thread-1, initial)>>: on_close() takes 1 positional argument but 2 were given File "/usr/lib/python3.9/site-packages/websocket/_app.py", line 388, in _callback callback(self, *args)

So I added 'ws' parameter to those functions (like https://github.com/rbrcsk/pushbullet.py/commit/01c791c13748aca9f55c1c3d51ed635f0a0f3fd4).

And that seems to have fixed the issue... Maybe 'ws' parameter is required in websocket-client 0.58.0?

$ pip install websocket-client Defaulting to user installation because normal site-packages is not writeable Requirement already satisfied: websocket-client in /usr/lib/python3.9/site-packages (0.58.0) Requirement already satisfied: six in /usr/lib/python3.9/site-packages (from websocket-client) (1.15.0)

blacklight commented 3 years ago

I can confirm the bug.

This is caused by this pull request on websocket-client (merged in 0.58.0), which is basically supposed to revert the previous behaviour (i.e. websocket object not passed to the callbacks).

In other words, it seems that the previous behaviour (where only the message was passed) was a bug, not a feature - although lots of applications that depend on websocket-client updated their code accordingly...

This has created a nasty situation where the callbacks require (ws, msg) on websocket-client < 0.53, (msg) for 0.53.0 <= websocket-client < 0.58.0, and again (ws, msg) for websocket-client >= 0.58.0.

I have created a pull request to fix this madness - the list of arguments on the callbacks should be dynamic, so we can figure out if the websocket object is being passed as a first argument or not. As a bonus, this makes pushbullet.py compatible with all the versions of websocket-client, regardless of the callback format, and it also removes potential issues about naming member functions as existing attributes on the WebSocketApp class.

@rbrcsk waiting for a review :)