JurajNyiri / pytapo

Python library for communication with Tapo Cameras
MIT License
277 stars 58 forks source link

Invalid authentication data #109

Open pa-t opened 4 months ago

pa-t commented 4 months ago

I have a c425 camera running firmware 1.3.5. I have been connecting to it with pytapo==3.3.19 via

tapo_camera = Tapo(host=CAMERA_ONE_IP, user=CAMERA_ONE_USERNAME, password=CAMERA_ONE_PASSWORD)

and up until today have not had any issues. I switched wifi networks today for the camera and had to reset the camera, now I cannot connect to the camera. I am getting this stack trace

Refreshing stok...
New request:
{'data': {'method': 'login', 'params': {'encrypt_type': '3', 'username': 'patrick'}}, 'headers': {'Host': 'REDACTED', 'Referer': 'REDACTED', 'Accept': 'application/json', 'Accept-Encoding': 'gzip, deflate', 'User-Agent': 'Tapo CameraClient Android', 'Connection': 'close', 'requestByApp': 'true', 'Content-Type': 'application/json; charset=UTF-8'}, 'verify': False}
200
{'result': {'data': {'code': -40401, 'time': 9, 'max_time': 10, 'encrypt_type': ['3'], 'key': 'REDACTED', 'nonce': 'REDACTED', 'device_confirm': 'REDACTED'}}, 'error_code': -40413}
Connection is secure.
New request:
{'data': {'method': 'login', 'params': {'cnonce': 'REDACTED', 'encrypt_type': '3', 'username': 'patrick'}}, 'headers': {'Host': 'REDACTED', 'Referer': 'REDACTED', 'Accept': 'application/json', 'Accept-Encoding': 'gzip, deflate', 'User-Agent': 'Tapo CameraClient Android', 'Connection': 'close', 'requestByApp': 'true', 'Content-Type': 'application/json; charset=UTF-8'}, 'verify': False}
200
{'result': {'data': {'code': -40401, 'time': 8, 'max_time': 10, 'encrypt_type': ['3'], 'key': 'REDACTED', 'nonce': 'REDACTED', 'device_confirm': 'REDACTED'}}, 'error_code': -40413}
Status code: 200
Processing secure response.
Validating device confirm.
Incorrect device_confirm value, retrying: 1/2.
Refreshing stok...
Connection is secure.
New request:
{'data': {'method': 'login', 'params': {'cnonce': 'REDACTED', 'encrypt_type': '3', 'username': 'patrick'}}, 'headers': {'Host': 'REDACTED', 'Referer': 'REDACTED', 'Accept': 'application/json', 'Accept-Encoding': 'gzip, deflate', 'User-Agent': 'Tapo CameraClient Android', 'Connection': 'close', 'requestByApp': 'true', 'Content-Type': 'application/json; charset=UTF-8'}, 'verify': False}
200
{'result': {'data': {'code': -40401, 'time': 7, 'max_time': 10, 'encrypt_type': ['3'], 'key': 'REDACTED', 'nonce': 'REDACTED', 'device_confirm': 'REDACTED'}}, 'error_code': -40413}
Status code: 200
Processing secure response.
Validating device confirm.
Incorrect device_confirm value, retrying: 2/2.
Refreshing stok...
Connection is secure.
New request:
{'data': {'method': 'login', 'params': {'cnonce': 'REDACTED', 'encrypt_type': '3', 'username': 'patrick'}}, 'headers': {'Host': 'REDACTED', 'Referer': 'REDACTED', 'Accept': 'application/json', 'Accept-Encoding': 'gzip, deflate', 'User-Agent': 'Tapo CameraClient Android', 'Connection': 'close', 'requestByApp': 'true', 'Content-Type': 'application/json; charset=UTF-8'}, 'verify': False}
200
{'result': {'data': {'code': -40401, 'time': 6, 'max_time': 10, 'encrypt_type': ['3'], 'key': 'REDACTED', 'nonce': 'REDACTED', 'device_confirm': 'REDACTED'}}, 'error_code': -40413}
Status code: 200
Processing secure response.
Validating device confirm.
Incorrect device_confirm value, raising Exception.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/anaconda3/envs/montreat_39/lib/python3.9/site-packages/pytapo/__init__.py", line 86, in __init__
    self.basicInfo = self.getBasicInfo()
  File "/opt/anaconda3/envs/montreat_39/lib/python3.9/site-packages/pytapo/__init__.py", line 1009, in getBasicInfo
    return self.executeFunction(
  File "/opt/anaconda3/envs/montreat_39/lib/python3.9/site-packages/pytapo/__init__.py", line 491, in executeFunction
    data = self.performRequest(
  File "/opt/anaconda3/envs/montreat_39/lib/python3.9/site-packages/pytapo/__init__.py", line 530, in performRequest
    self.ensureAuthenticated()
  File "/opt/anaconda3/envs/montreat_39/lib/python3.9/site-packages/pytapo/__init__.py", line 108, in ensureAuthenticated
    return self.refreshStok()
  File "/opt/anaconda3/envs/montreat_39/lib/python3.9/site-packages/pytapo/__init__.py", line 418, in refreshStok
    return self.refreshStok(loginRetryCount)
  File "/opt/anaconda3/envs/montreat_39/lib/python3.9/site-packages/pytapo/__init__.py", line 418, in refreshStok
    return self.refreshStok(loginRetryCount)
  File "/opt/anaconda3/envs/montreat_39/lib/python3.9/site-packages/pytapo/__init__.py", line 423, in refreshStok
    raise Exception("Invalid authentication data")
Exception: Invalid authentication data

Looking for any guidance here on what could be wrong. As far as i can tell in my debugging is that there is an issue with the nonce here

if self.validateDeviceConfirm(
    nonce, responseData["result"]["data"]["device_confirm"]
)
JurajNyiri commented 4 months ago

https://github.com/JurajNyiri/HomeAssistant-Tapo-Control/issues/551

pa-t commented 4 months ago

@JurajNyiri that is odd though, I am fairly certain that it worked before on the same firmware. Is the only way forward to downgrade? Any plans to get this working on newer firmware versions?

pa-t commented 4 months ago

Also I am on 1.3.5, not 1.3.8 or higher

JurajNyiri commented 4 months ago

All the information is in the ticket I linked above including answers to your exact questions.

fmarzocca commented 3 months ago

All the information is in the ticket I linked above including answers to your exact questions.

that ticket is blocked. How do we get informed when fixed?

JurajNyiri commented 3 months ago

@fmarzocca You can read the top post and the updates posted there.