almottier / TapoP100

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

Error reconnecting within script: 403 Client Error: Forbidden for url: http://xxx.xxx.x.xx/app/request?seq=116114337 #19

Open bunbunet opened 8 months ago

bunbunet commented 8 months ago

Hello, I wrote a script that control a lamp color based on the decibel levels measured by a microphone. I'm using it to help customers of a winery out of my windows to control the loudness of their voices. The script runs automatically every night in a raspberry pi. To deal disconnections and reconnections I added to the script a function that goes like this

connection=False
def connect_lamp():
    try:
        global l530sec
        l530sec = PyL530.L530("xxx.xxx.xxx", "me@mymail", "mypassowrd")

        l530sec.handshake() #Creates the cookies required for further methods
        l530sec.login() #Sends credentials to the plug and creates AES Key and IV for further methods
        global connection
        connection=True

    except Exception as e:
        #print(e)
        connection=False
        return

while connection==False:
    connect_lamp()

This function work perfectly if the lamp is offline when the script is started, but if the connection is lost afterwards it give the 403 Client Error: Forbidden for etc.. I can share the entire script here or on my github, any suggestion will be greatly appreciated, having this script running properly is of vital importance!!

Thank you very much

Federico

almottier commented 8 months ago

Hello,

handshake() and login() are deprecated in this fork. You may not need them. Why not create a new l530sec whenever you want to change the color ?

l530sec = PyL530.L530("xxx.xxx.xxx", "me@mymail", "mypassowrd")
l530sec.setColor(...)

I do this on a low-end raspberry pi zero, it is very fast.