fishbigger / TapoP100

A module for controlling the TP-Link Tapo P100 Plugs
MIT License
566 stars 138 forks source link

Invalid Request or Credentials with p110 #101

Open thefffilo opened 1 year ago

thefffilo commented 1 year ago

I get the "Invalid Request or Credentials" error in login() when I try to login in my p110. I checked credentials, I tried changing psw, I tried removing the plug from the tapo app ad re-adding it. Is anyone having the same problem? What could it be? Firmware v. 1.1.6 Build 221114 Rel. 203339, Is this supported? Thanks guys.

Error:

`Traceback (most recent call last):
  File "/home/filippo/.local/lib/python3.10/site-packages/PyP100/PyP100.py", line 168, in login
    self.token = ast.literal_eval(decryptedResponse)["result"]["token"]
KeyError: 'result'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/filippo/pythonDir/prova.py", line 7, in <module>
    p110.login()
  File "/home/filippo/.local/lib/python3.10/site-packages/PyP100/PyP100.py", line 172, in login
    raise Exception(f"Error Code: {errorCode}, {errorMessage}")
Exception: Error Code: -1501, Invalid Request or Credentials`
DaneelReventelov commented 1 year ago

I have the same problem but with Tapo100 but the Tapo110 on the same net works!

Traceback (most recent call last): File "C:\Users***\AppData\Local\Programs\Python\Python39\lib\site-packages\PyP100\PyP100.py", line 168, in login self.token = ast.literal_eval(decryptedResponse)["result"]["token"] KeyError: 'result'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 1, in File "C:\Users***\AppData\Local\Programs\Python\Python39\lib\site-packages\PyP100\PyP100.py", line 172, in login raise Exception(f"Error Code: {errorCode}, {errorMessage}") Exception: Error Code: -1501, Invalid Request or Credentials

Tapo 100 firmware (not works): 1.4.10 Build 202111104 rel 35882 Tapo 110 firmware (works): 1.1.6 Build 221114 Rel 203339

I think also my Tapo 110 will not works when the firmware updates.

DaneelReventelov commented 1 year ago

Solved: revert to previous time parameter in login function Payload = { "method":"login_device", "params":{ "password": p100.encodedPassword, "username": p100.encodedEmail }, "requestTimeMils": int(round(time.time() * 1000)), }

Before was "requestTimeMils": 0, to solve -1501 error instead now is the problem

I hope the developer change and test this soon :P

fishbigger commented 1 year ago

I tested both extensively before I made the change and changing to 0 definitely fixed this issue. So I'm not entirely sure what is going on here.

tnmendes commented 1 year ago

@fishbigger are you living in Europe? Right now you are using the server "https://eu-wap.tplinkcloud.com" (Europe Server) which is an old server from TP-Link. Right now there are using new servers, for login I recommend using the global server, this one: "https://n-wap-gw.tplinkcloud.com"

Example: URL: {{server_global}}/?appName=TP-Link_Tapo_Android&appVer=2.2.29&netType=wifi&termID=11-11-11-96-48-EB&ospf=Android%204.4.2&locale=en_US

{
  "method": "login",
  "params": {
    "appType": "TP-Link_Kasa_Android",
    "appVersion": "2.27.0",
    "cloudPassword": "password",
    "cloudUserName": "email",
    "platform": "Android 10",
    "terminalUUID": "11-11-11-96-48-EB",
    "refreshTokenNeeded": true
  }
}

Adding the refreshTokenNeeded, helps to avoid using the password all the time. I hope this helps you

rhuijben commented 1 year ago

Was able to get my P100 plugs working again by updating all the requestTimeMils values to that old code.

I'm guessing this value is used to de-duplicate requests . We should probably send something that changes more often than every second using a better precision clean clock.

CrimsonBinome24 commented 1 year ago

Good day, I am seeing this same behavior on L530e Bulbs, changing the requestTimeMils has no effect. If any additional information is needed let me know.

markschechter commented 1 year ago

Getting the same error here. Tried making the requestTimeMils update but no dice.

My code (with creds redacted):

Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyP100 import PyP100
>>> 
>>> p100 = PyP100.P100("IP-ADDRESS", "EMAIL", "PASSWORD") #Creates a P100 plug object
>>> 
>>> p100.handshake() #Creates the cookies required for further methods
>>> p100.login() #Sends credentials to the plug and creates AES Key and IV for further methods
>>> 
>>> p100.turnOffWithDelay(200) #Turns the connected plug off after 1 mins
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.local/lib/python3.9/site-packages/PyP100/PyP100.py", line 351, in turnOffWithDelay
    decryptedResponse = self.tpLinkCipher.decrypt(r.json()["result"]["response"])
KeyError: 'result'

I'm using a Tapo P100 smart plug, Firmware: 1.3.6 Build 20210827 Rel. 37578

markschechter commented 1 year ago

Mine just started working for no reason as of yesterday.... I don't use it regularly but will continue to monitor....

CrimsonBinome24 commented 1 year ago

Still experiencing this issue as of today.

I dismantled one of my bulbs and gained access to its uart, but have had minimal luck getting any information out of it.

I may try to man in the middle communication between the app and my light this weekend.

If any further information is required I will do my best to provide it.

anzgar01 commented 1 year ago

I am also still having this issue, any clue on what to do to get it to work?

p100.login() #Sends credentials to the plug and creates AES Key and IV for further methods

File "/home/piadmin/.local/lib/python3.9/site-packages/PyP100/PyP100.py", line 172, in login raise Exception(f"Error Code: {errorCode}, {errorMessage}") Exception: Error Code: -1501, Invalid Request or Credentials

anzgar01 commented 1 year ago

Allright, I found something that fixed it for me at least: Reinstall PyP100 and use an older version, for me 0.0.25 is working like a charm.

pip install --force-reinstall -v "PyP100==0.0.25"

CrimsonBinome24 commented 1 year ago

I'll give it a try tonight

On Mon, Mar 13, 2023, 04:27 anzgar01 @.***> wrote:

Allright, I found something that fixed it for me at least: Reinstall PyP100 and use an older version, for me 0.0.25 is working like a charm.

pip install --force-reinstall -v "PyP100==0.0.25"

— Reply to this email directly, view it on GitHub https://github.com/fishbigger/TapoP100/issues/101#issuecomment-1465705102, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB3S2V55E6ZF24QW5WGM4PLW33LAHANCNFSM6AAAAAAUYTDRQM . You are receiving this because you commented.Message ID: @.***>

tarkilhk commented 1 year ago

Did you guys manage to make it work in the end? I'm looking to buy some smart plugs to monitor my home energy consumption, and I'm trying to find a model that "works".

Thanks in advance for your answers! :)

markschechter commented 1 year ago

I tried the suggested fixes, they didn't work, so I rolled back. Started working after that... so yes, it is working... for me at least.... A piece of advice, I purchased my Tapo plug because it was a cheaper smart-plug option but in retrospect, I probably would have purchased from a manufacturer who is more API-friendly. Depends on how much you need to rely on the automation you tend to create with this app. Just my 2 cents.

CrimsonBinome24 commented 1 year ago

None of the fixes worked for me, wound up just going to a zigbee system so I could support it without a 3rd party api.

On Mon, Apr 10, 2023, 12:46 markschechter @.***> wrote:

I tried the suggested fixes, they didn't work, so I rolled back. Started working after that... so yes, it is working... for me at least.... A piece of advice, I purchased my Tapo plug because it was a cheaper smart-plug option but in retrospect, I probably would have purchased from a manufacturer who is more API-friendly. Depends on how much you need to rely on the automation you tend to create with this app. Just my 2 cents.

— Reply to this email directly, view it on GitHub https://github.com/fishbigger/TapoP100/issues/101#issuecomment-1502045756, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB3S2VYU24IFZNB56GPV4Z3XAQ2PPANCNFSM6AAAAAAUYTDRQM . You are receiving this because you commented.Message ID: @.***>

konbick commented 1 year ago

Allright, I found something that fixed it for me at least: Reinstall PyP100 and use an older version, for me 0.0.25 is working like a charm.

pip install --force-reinstall -v "PyP100==0.0.25"

Thanks, this worked for me and the P100