fishbigger / TapoP100

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

Problem running code for Tapo P110 #92

Closed RobertVoorn1977 closed 1 year ago

RobertVoorn1977 commented 1 year ago

The following code works on my ubuntu machine, but does not work on my Macbook pro laptop:

from PyP100 import PyP110

p110 = PyP110.P110("192.168.X.X", "<email address>", "<password>") #Creates a P110 plug object

p110.handshake() #Creates the cookies required for further methods
p110.login() #Sends credentials to the plug and creates AES Key and IV for further methods

print(p110.getDeviceInfo()) #Returns dict with all the device info of the connected plug
print(p110.getDeviceName()) #Returns the name of the connected plug set in the app

When I run this code on the Macbook I get the following error:

/Users/robafett/PycharmProjects/BatterySaver/venv/bin/python /Users/robafett/PycharmProjects/BatterySaver/smart_plug_test2.py
Traceback (most recent call last):
  File "/Users/robafett/PycharmProjects/BatterySaver/venv/lib/python3.9/site-packages/requests/models.py", line 910, in json
    return complexjson.loads(self.text, **kwargs)
  File ["/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py"](mailto:/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py), line 346, in loads
    return _default_decoder.decode(s)
  File ["/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py"](mailto:/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py), line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File ["/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py"](mailto:/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py), line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/robafett/PycharmProjects/BatterySaver/smart_plug_test2.py", line 8, in <module>
    print(p110.getDeviceInfo()) #Returns dict with all the device info of the connected plug
  File "/Users/robafett/PycharmProjects/BatterySaver/venv/lib/python3.9/site-packages/PyP100/PyP100.py", line 256, in getDeviceInfo
    decryptedResponse = self.tpLinkCipher.decrypt(r.json()["result"]["response"])
  File "/Users/robafett/PycharmProjects/BatterySaver/venv/lib/python3.9/site-packages/requests/models.py", line 917, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: [Errno Expecting value] <html><body><center>200 OK</center></body></html>: 0

I am a Java programmer and am not familiar enough with Python to interpret this stacktrace to solvefind the issue. I use the same version of the library (newly installed on the ubuntu machine and updated to the newest on the Macbook, where it has worked before) and also identical credentials on both machines.

RobertVoorn1977 commented 1 year ago

I found out that the versions were not entirely the same, even after I updated the library on the Macbook using the suggested command. Removed the library and added it again and it works now. So closing this issue.