Skip to content

0.2.0rc2 websocket communication issues #149

@bitphage

Description

@bitphage

During testing dexbot Codaone/DEXBot#335 I found several issues. websocket-client I used has 0.53.0 version.

  1. self.user and self.password have type "function". The first line of output is print(locals()) inside def rpcexec().
{'payload': {'method': 'call', 'params': [1, 'login', [<function Api.__getattr__.<locals>.func at 0x7f0443d3c6a8>, <function Api.__getattr__.<locals>.func at 0x7f0443e788c8>]], 'jsonrpc': '2.0', 'id': 1}, 'self': <bitsharesapi.websocket.BitSharesWebsocket object at 0x7f0442640780>}
error from callback <bound method BitSharesWebsocket.on_open of <bitsharesapi.websocket.BitSharesWebsocket object at 0x7f0442640780>>: Object of type 'function' is not JSON serializable
  File "/home/vvk/.local/share/virtualenvs/DEXBot-XTl2tJdV/lib/python3.6/site-packages/websocket/_app.py", line 333, in _callback
    callback(*args)
  File "/home/vvk/.local/share/virtualenvs/DEXBot-XTl2tJdV/lib/python3.6/site-packages/bitsharesapi/websocket.py", line 166, in on_open
    self.login(self.user, self.password, api_id=1)
  File "/home/vvk/.local/share/virtualenvs/DEXBot-XTl2tJdV/lib/python3.6/site-packages/bitsharesapi/websocket.py", line 391, in method
    r = self.rpcexec(query)
  File "/home/vvk/.local/share/virtualenvs/DEXBot-XTl2tJdV/lib/python3.6/site-packages/bitsharesapi/websocket.py", line 356, in rpcexec
    log.debug(json.dumps(payload))
  File "/usr/lib/python3.6/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.6/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.6/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.6/json/encoder.py", line 180, in default
    o.__class__.__name__)

Why they have type function? This because of bitshares/notify.py init BitSharesWebsocket as

        self.websocket = BitSharesWebsocket(
            urls=self.blockchain.rpc.urls,
            user=self.blockchain.rpc.user,
            password=self.blockchain.rpc.password,
            accounts=accounts,
            markets=self.get_market_ids(markets),
            objects=objects,
            on_tx=on_tx,
            on_object=on_object,
            on_block=on_block,
            on_account=self.process_account,
            on_market=self.process_market,
            keep_alive=keep_alive
        )

see these user=self.blockchain.rpc.user,.

  1. All callback functions should have ws=None or no ws at all. For example, on_message produces an error:
error from callback <bound method BitSharesWebsocket.on_message of <bitsharesapi.websocket.BitSharesWebsocket object at 0x7f979271d710>>: on_message() missing 1 required positional argument: 'reply'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions