Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot connect to Tapo P100 #128

Open
buzzdx opened this issue Oct 12, 2023 · 19 comments
Open

Cannot connect to Tapo P100 #128

buzzdx opened this issue Oct 12, 2023 · 19 comments

Comments

@buzzdx
Copy link

buzzdx commented Oct 12, 2023

Hey there, today we got our first Tapo P100 smartplug. Before buying it I looked into controlling it via Python and found this library. I setup the plug via the app and everything works fine, however when trying to use your example code I always get the following error:

File "#PATH#", line 133, in handshake
encryptedKey = r.json()["result"]["key"]
KeyError: 'result'

I printed out the return value (r.json()) of the post method in your code and get this result:

{"error_code":1003}

The App shows the following information about the plug:

Hardware Version 2
Firmware 1.2.1 Build 230804 Rel. 190922

Since I'm using your example code (with my credentials and ip of course) I don't think it's a usage problem. Did the API maybe change and the code needs to be updated? I hope someone can help =)

@almottier
Copy link

Duplicate of #123

@kebos00
Copy link

kebos00 commented Oct 12, 2023

For me the handshake problem with the P100 has arisen after the change of firmware from 1.1.0 to 1.2.1 to fix a security bug. This is a shame as I had just started using these functions with a P100 and was amazed that it worked so well until I did a firmware update. I'm now holding off updating my other P100s which are still OK for now. I do hope someone can find a fix.

@almottier
Copy link

@kebos00 try this fork: https://github.com/almottier/TapoP100 , it works for P100 version 1.2.1

@kebos00
Copy link

kebos00 commented Oct 13, 2023

That's great! I didn't know if I had to uninstall the previous Py100 but as I wasn't sure how to I just installed your fork anyway.
Installing your link failed the first time but worked when I used pip3. Now the P100 is controllable again thanks.
Note to anyone else that using the fork will no longer support firmware before 1.2.1.

@almottier
Copy link

Hello @kebos00 , I added support for old firmware using a fallback to the old authentification mechanism.

@kebos00
Copy link

kebos00 commented Oct 15, 2023

I installed your new code but if I use it on old firmware I get the following error. It could be me doing something wrong of course but it still works fine on the latest firmware.

raise Exception(f"Failed to initialize device: {e}")

Exception: Failed to initialize device: Failed to authenticate

@almottier
Copy link

@kebos00 I think you are still using the old version.
Could you try running this command to re-install the package:

pip install --force-reinstall git+https://github.com/almottier/TapoP100.git@main

@kebos00
Copy link

kebos00 commented Oct 15, 2023

Thanks. I've done that.
I now find that the first time I create the P100 plug object I get an error as below but then it continues and operates the P100 correctly with subsequent P100.turnOn() and P100.turnOff() commands.
I guess that after the initial fail which it reports, it then tries the old authentication which then works.

Failed to initialize protocol AuthProtocol
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/PyP100/PyP100.py", line 23, in _initialize
protocol.Initialize()
File "/home/pi/.local/lib/python3.7/site-packages/PyP100/auth_protocol.py", line 109, in Initialize
raise Exception("Failed to authenticate")
Exception: Failed to authenticate

@almottier
Copy link

Yes, the error message is expected as it will first try the new authentication protocol. It could be avoided by using an optional parameter passing the protocol to use.

@kebos00
Copy link

kebos00 commented Oct 15, 2023

Thank you very much. Your fix is much appreciated!

@hams-i
Copy link

hams-i commented Oct 22, 2023

Hi dude @almottier thank you for new fork, how did you fix it? can you explain?

@almottier
Copy link

Hello @hams-i ,
It is explained in the forks README. I took the code from another project supporting the new auth and adapted it to be retro-compatible with TapoP100.
I may create a new pip package as the maintainer @fishbigger looks no longer active.

@RFNO
Copy link

RFNO commented Oct 29, 2023

Hello, I still have an result error. I'm using handshake and login otherwise I get an errot ('P100' object has no attribute 'token'), but these methods are deprecated, how to replace them ?

@almottier
Copy link

almottier commented Oct 29, 2023

Hi @RFNO
Did you try to install the fork like this?

pip install --force-reinstall git+https://github.com/almottier/TapoP100.git@main

You should not need to call login or handshake. If you still have a problem, please open an Issue in the fork with the error details.

@RFNO
Copy link

RFNO commented Oct 29, 2023

No, so I try ... The install get no error but ... Still 'P100' object has no attribute 'token'

Nevertheless, it works with library tapo (but harder to use)

@RFNO
Copy link

RFNO commented Nov 6, 2023

I tried again but the command doesn't work with windows...

ERROR: Error [WinError 2] Le fichier spécifié est introuvable while executing command git version
ERROR: Cannot find command 'git' - do you have 'git' installed and in your PATH?

It works with git installed, and now your library works too. Thank you for your work.

@baishi
Copy link

baishi commented Nov 27, 2023

I confirm @almottier 's fix works for me. Thanks for the contribution @almottier !

@Eserim
Copy link

Eserim commented Jan 29, 2024

Many thanks for this - I've had to resort to this as the official control app wouldn't allow me to create an automation with a quick on then off in order to control a fish tank light that uses that to toggle the mode.

@mrx23dot
Copy link
Contributor

So I was stupid enough to update the firmware on Tapo L510 light bulb to v1.3.1.

This branch works for me:
https://github.com/almottier/TapoP100

I use it as a sunrise simulator before the alarm clock goes off, it became essential in winter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants