1

I'm trying to turn on my TP-Link HS110 from AWS Lambda. I'm using Python 3.6. I imported json and requests into Lambda, this seems to work fine. Its actually performing the request, but the TP-Link Cloud Api is responding with [error_code:-20651, msg:Token expired]. But the token is working (double checked), if I use cURL so thats not the problem. Also generated a new token but stil not working in Lambda. Does anyone see an error in the code or knows about this issue?

url = 'https://eu-wap.tplinkcloud.com/?token=token HTTP/1.1'    
payload = {
            "method":"passthrough",
            "params": 
                      { "deviceId": "abc", 
                        "requestData": "{\"system\":{\"set_relay_state\":{\"state\":1}}}" 
                      }

          }
payload = json.dumps(payload)  
response = requests.post(url,payload,{'Content-Type': 'application/json'})
ItseMe
  • 11
  • 1
  • I replaced the actual token with "token" and deviceId with "abc" – ItseMe Jun 06 '18 at 22:38
  • Welcome to Stack Overflow! Use formatting tools to make your post more readable. Code block should look like `code block`. Use **bold** *italics* if needed. – Morse Jun 06 '18 at 22:52
  • add user agent and connection keep alive `'User-Agent': blah-blah Connection: Keep-Alive 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'` – Morse Jun 06 '18 at 22:56
  • Thank you very much for your fast reply. I found the solution...its way more trivial. I just removed HTTP/1.1 from the URL and its working. – ItseMe Jun 07 '18 at 09:39
  • Great! I was thinking the same but some documentations online had it. May be `requests` doesnt need that. – Morse Jun 07 '18 at 12:30

0 Answers0