rospogrigio / localtuya

local handling for Tuya devices
GNU General Public License v3.0
3k stars 565 forks source link

Updating from 3.1 to master results in .JSONDecodeError: Expecting value: line 1 column 1 (char 0) #258

Closed bigretromike closed 3 years ago

bigretromike commented 3 years ago

Logger: custom_components.localtuya.common
Source: custom_components/localtuya/pytuya/__init__.py:559
Integration: LocalTuya integration (documentation, issues)
First occurred: 14:38:04 (180 occurrences)
Last logged: 14:53:01
[646...a6f] Connect to 192.168.1.31 failed

Traceback (most recent call last):
  File "/config/custom_components/localtuya/common.py", line 149, in _make_connection
    status = await self._interface.status()
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 472, in status
    status = await self.exchange(STATUS)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 457, in exchange
    payload = self._decode_payload(msg.payload)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 559, in _decode_payload
    return json.loads(payload)
  File "/usr/local/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
postlund commented 3 years ago

Strange, wouldn't expect that kind of error. Please enable debug logs and include them here.

https://github.com/rospogrigio/localtuya#debugging

bigretromike commented 3 years ago

I added:

logger:
  default: warning
  logs:
    custom_components.localtuya: debug

to configuration.yaml

2020-12-18 15:01:16 ERROR (MainThread) [custom_components.localtuya.common] [700...d2a] Connect to 192.168.0.43 failed
Traceback (most recent call last):
File "/config/custom_components/localtuya/common.py", line 139, in _make_connection
self._interface = await pytuya.connect(
File "/config/custom_components/localtuya/pytuya/__init__.py", line 637, in connect
_, protocol = await loop.create_connection(
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1025, in create_connection
raise exceptions[0]
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1010, in create_connection
sock = await self._connect_sock(
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 924, in _connect_sock
await self.sock_connect(sock, address)
File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 496, in sock_connect
return await fut
File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 528, in _sock_connect_cb
raise OSError(err, f'Connect call failed {address}')
OSError: [Errno 113] Connect call failed ('192.168.0.43', 6668)
2020-12-18 15:01:16 DEBUG (MainThread) [custom_components.localtuya.pytuya] [646...a6f] Dispatching message TuyaMessage(seqno=0, cmd=8, retcode=0, payload=b'3.3\x00\x00\x00\x00\x00\x00\x00\x12\x00\x00\x00\x01\x0c\xf5+\x1c\xef\xc7\n;\x9f\x16EN4;N\xd6\x05\xb2\xc6\x9e<\xb9>\x08)\xe5\x1az\xca\x99\x85\x9eN\xc1\xc6{]J\x83\x9c\x0f\xab\xdf\x05+\xe6|\xd1\xe68Z\xaf\xd50( u\xa9K\xa8\xbcp\xd6Ip\x07W]"\xe2B\x89\xd4,\x89\x18L\xc5\xf7\xed', crc=1735151287)
2020-12-18 15:01:16 DEBUG (MainThread) [custom_components.localtuya.pytuya] [646...a6f] Got status update
2020-12-18 15:01:16 DEBUG (MainThread) [custom_components.localtuya.pytuya] [646...a6f] Decrypted payload:
2020-12-18 15:01:16 ERROR (MainThread) [homeassistant] Error doing job: Fatal error: protocol.data_received() call failed.
Traceback (most recent call last):
File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 862, in _read_ready__data_received
self._protocol.data_received(data)
File "/config/custom_components/localtuya/pytuya/__init__.py", line 403, in data_received
self.dispatcher.add_data(data)
File "/config/custom_components/localtuya/pytuya/__init__.py", line 279, in add_data
self._dispatch(TuyaMessage(seqno, cmd, retcode, payload, crc))
File "/config/custom_components/localtuya/pytuya/__init__.py", line 297, in _dispatch
self.listener(msg)
File "/config/custom_components/localtuya/pytuya/__init__.py", line 363, in _status_update
decoded_message = self._decode_payload(msg.payload)
File "/config/custom_components/localtuya/pytuya/__init__.py", line 559, in _decode_payload
return json.loads(payload)
File "/usr/local/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python3.8/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
2020-12-18 15:01:16 DEBUG (MainThread) [custom_components.localtuya.pytuya] [646...a6f] Connection lost: Expecting value: line 1 column 1 (char 0)
...
2020-12-18 15:01:21 ERROR (MainThread) [custom_components.localtuya.common] [646...a6f] Connect to 192.168.0.31 failed
Traceback (most recent call last):
File "/config/custom_components/localtuya/common.py", line 149, in _make_connection
status = await self._interface.status()
File "/config/custom_components/localtuya/pytuya/__init__.py", line 472, in status
status = await self.exchange(STATUS)
File "/config/custom_components/localtuya/pytuya/__init__.py", line 457, in exchange
payload = self._decode_payload(msg.payload)
File "/config/custom_components/localtuya/pytuya/__init__.py", line 559, in _decode_payload
return json.loads(payload)
File "/usr/local/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python3.8/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
...
bigretromike commented 3 years ago

Do you need more logs ?

postlund commented 3 years ago

Those will do! I have probably messed something up. Can you email me the local key if the device?

bigretromike commented 3 years ago

Those will do! I have probably messed something up. Can you email me the local key if the device?

You should have them on mail.

postlund commented 3 years ago

I think we concluded that the local key is wrong (old), but @bigretromike will have to confirm that. Please close the issue if that was the case.

bigretromike commented 3 years ago

@postlund, yes. Looks like the key was wrong. thanks with debugging process