defi-sdk-py icon indicating copy to clipboard operation
defi-sdk-py copied to clipboard

Websocket: Attempt to decode JSON with unexpected mimetype: text/plain; charset=utf-8

Open wjmelements opened this issue 4 years ago • 1 comments

I am trying to use a websocket uri for the sdk. Maybe it's not supported, but here is the error. I did not see the error when using http.

Version 0.0.4.

Traceback (most recent call last):
  File "~/.local/share/virtualenvs/prj-XTuW3tpY/lib/python3.7/site-packages/defisdk/repositories/ethereum.py", line 24, in call_method
    node_answer = await self._post(url=self.url.url, headers=headers, data=data)
  File "~/.local/share/virtualenvs/prj-XTuW3tpY/lib/python3.7/site-packages/defisdk/repositories/base.py", line 18, in _post
    return await r.json()
  File "~/.local/share/virtualenvs/prj-XTuW3tpY/lib/python3.7/site-packages/aiohttp/client_reqrep.py", line 1103, in json
    headers=self.headers,
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/plain; charset=utf-8', url=URL('ws://192.168.0.15:8546')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "~/.local/share/virtualenvs/prj-XTuW3tpY/lib/python3.7/site-packages/defisdk/repositories/ethereum.py", line 26, in call_method
    raise EthereumNodeResponseException(params, e.message, e.code, e.response)
AttributeError: 'ContentTypeError' object has no attribute 'response'

During handling of the above exception, another exception occurred:
    
    ...

     = await defi_sdk.get_token_components(
  File "~/.local/share/virtualenvs/prj-XTuW3tpY/lib/python3.7/site-packages/defisdk/__init__.py", line 84, in get_token_components
    return await self._repository.get_token_components(token_type, token_address, block)
  File "~/.local/share/virtualenvs/prj-XTuW3tpY/lib/python3.7/site-packages/defisdk/repositories/defi.py", line 187, in get_token_components
    full_token_balance = await self.get_full_token_balance(token_type, token_address, block)
  File "~/.local/share/virtualenvs/prj-XTuW3tpY/lib/python3.7/site-packages/defisdk/repositories/defi.py", line 159, in get_full_token_balance
    block=block
  File "~/.local/share/virtualenvs/prj-XTuW3tpY/lib/python3.7/site-packages/defisdk/repositories/ethereum.py", line 42, in _call
    node_answer = await self.call_method('eth_call', params)
  File "~/.local/share/virtualenvs/prj-XTuW3tpY/lib/python3.7/site-packages/defisdk/repositories/ethereum.py", line 28, in call_method
    if not node_answer.get('result'):
AttributeError: 'NoneType' object has no attribute 'get'

wjmelements avatar Dec 18 '20 23:12 wjmelements

Hey @wjmelements, thanks for reporting! Web socket URIs are indeed not supported atm but it's a great feature request for the future versions.

bashalex avatar Dec 21 '20 15:12 bashalex