JurajNyiri / pytapo

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

How to use? / Dont work with useraccount and "admin" #87

Closed solisinvictum closed 9 months ago

solisinvictum commented 9 months ago

Like the Titel says.

Quiet dont understand how to use it.

Installed pytapo, created "device account" on the tapo app (it works, zoneminder use it already over rtsp).

Created a test.py like described:

from pytapo import Tapo

user = "admin" # user you set in Advanced Settings -> Camera Account
password = "yopasswordsecret" # password you set in Advanced Settings -> Camera Account
host = "192.168.5.226" # ip of the camera, example: 192.168.1.52

tapo = Tapo(host, user, password)

print(tapo.getBasicInfo())

Tried user, the user i set in the app. both dont work:

#: python test.py 
Traceback (most recent call last):
  File "/home/user/test.py", line 7, in <module>
    tapo = Tapo(host, user, password)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 86, in __init__
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 1009, in getBasicInfo
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 491, in executeFunction
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 530, in performRequest
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 108, in ensureAuthenticated
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 418, in refreshStok
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 418, in refreshStok
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 423, in refreshStok
Exception: Invalid authentication data

What i try to do, is to be able to move and tilt my camera.

JurajNyiri commented 9 months ago

For admin account use your tplink cloud pwd.

JurajNyiri commented 9 months ago

Make sure you are using latest version. Unblock camera in firewall so that it can reach internet. Remove from app. Factory reset. Add back to app. Thanks to that it will load correct cloud pwd. Use "admin" and your tplink cloud pwd.

Also try waiting. Camera blocks you after too many failed attempts for 1 hour.

solisinvictum commented 9 months ago

Why gets the Issue closed, if the Issue isnt confirmed solved? Nvm.

Make sure you are using latest version. Unblock camera in firewall so that it can reach internet. Remove from app. Factory reset. Add back to app. Thanks to that it will load correct cloud pwd. Use "admin" and your tplink cloud pwd.

Still dont work.

Log:

Traceback (most recent call last):
  File "/home/user/test.py", line 7, in <module>
    tapo = Tapo(host, user, password)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 86, in __init__
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 1009, in getBasicInfo
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 491, in executeFunction
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 530, in performRequest
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 108, in ensureAuthenticated
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 418, in refreshStok
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 418, in refreshStok
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 423, in refreshStok
Exception: Invalid authentication data

After that i factory reset again, added back to app again, configured again. Removed even from zoneminder etc.

Still, after a wait of over a hour, still dont work.

PS: Tapo C200 is the Device. Latest Firmware.

JurajNyiri commented 9 months ago

Because it works for hundreds others with this exact configuration with no issues and it's support question not an actual issue that needs to be fixed.

Anyways. Tell me exactly what you have done. What Tapo version you use, what camera firmware as well as enable debug logs and post that.

solisinvictum commented 9 months ago

-Tapoversion: Latest from Google Play available for Google Pixel 7 Pro. Version 3.1.315(1065) -Tapo C200 Version 1.3.9 Build 231019 Rel.29120n(4555)

What i have done:

-Exactly what the App wanted. Everything works on the App. Created local account under advanced settings (user: userab, password: the same like for the cloud. both works (can log in the app, and can watch rtsp stream with that password)). -Intalled pytapo, created test.py with the content like posted. -executed the script with python test.py (as user and root, linux)

[...]as well as enable debug logs and post that.

how do i enable debug logs pytapo?

JurajNyiri commented 9 months ago

What pytapo version are you using?

Set printDebugInformation to true in initializer of pytapo.

solisinvictum commented 9 months ago

What pytapo version are you using?

git. so the latest available. 20 Nov. 2023.

Set printDebugInformation to true in initializer of pytapo.

How i do that? I dont have a init.py file on my System:

grafik
JurajNyiri commented 9 months ago

Pass it to the pytapo initializer inside function Tapo(host, user, password)

solisinvictum commented 9 months ago
New request:
{'data': {'method': 'login', 'params': {'encrypt_type': '3', 'username': 'admin'}}, '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
{'error_code': -40413, 'result': {'data': {'code': -40401, 'encrypt_type': ['3'], 'key': 'REDACTED', 'nonce': 'REDACTED', 'device_confirm': 'REDACTED'}}}
Connection is secure.
New request:
{'data': {'method': 'login', 'params': {'cnonce': 'REDACTED', 'encrypt_type': '3', 'username': 'admin'}}, '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
{'error_code': -40413, 'result': {'data': {'code': -40401, 'encrypt_type': ['3'], 'key': 'REDACTED', 'nonce': 'REDACTED', 'device_confirm': 'REDACTED'}}}
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': 'admin'}}, '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
{'error_code': -40413, 'result': {'data': {'code': -40401, 'encrypt_type': ['3'], 'key': 'REDACTED', 'nonce': 'REDACTED', 'device_confirm': 'REDACTED'}}}
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': 'admin'}}, '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
{'error_code': -40413, 'result': {'data': {'code': -40401, 'encrypt_type': ['3'], 'key': 'REDACTED', 'nonce': 'REDACTED', 'device_confirm': 'REDACTED'}}}
Status code: 200
Processing secure response.
Validating device confirm.
Incorrect device_confirm value, raising Exception.
Traceback (most recent call last):
  File "/home/user/test.py", line 7, in <module>
    tapo = Tapo(host, user, password, printDebugInformation=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 86, in __init__
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 1009, in getBasicInfo
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 491, in executeFunction
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 530, in performRequest
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 108, in ensureAuthenticated
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 418, in refreshStok
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 418, in refreshStok
  File "/usr/lib/python3.11/site-packages/pytapo-3.3.18-py3.11.egg/pytapo/__init__.py", line 423, in refreshStok
Exception: Invalid authentication data
JurajNyiri commented 9 months ago

Thank you.

Camera is refusing the password you are entering.

As I said before, make sure password is correct. Make sure camera can reach internet. Remove it, factory reset and add back to app. Then try again after an hour of no tries at all.

There is nothing else I can help you with since I do not know your environment and it does work provided you follow all the steps correctly.

solisinvictum commented 9 months ago

I followed all steps correctly.

the password is exactly the same like for the cloud. everything else you mentioned i already tried.

Dont know if it helps, but ispy works and https://github.com/oparm/zoneminder-tapo-c200 works too. both can control. (same cloud password + user is admin)

I stay with ispy for now.