Closed mozo178 closed 5 years ago
Thanks for the bug report. Let's see if we can get your plug working.
Can I get you to print the response variable on line 168? The string is perhaps not the correct format.
Hi, Please help me how I can do that, which command should I use, etc. I am not good in this.
Sure and sorry for the late reply.
Find line 168 in the file pyW2115.py in the folder pyW215 and add the following print statement,
if recursive or return_value is None:
_LOGGER.warning("Failed to open url to {}".format(self.ip))
self._error_report = True
return None
else:
return return_value
print(response) # <---- This is the only change on line 167
xmlData = response.read().decode()
root = ET.fromstring(xmlData)
Then run your normal command to execute the script and you should get more information about the response variable. Try sending that to me and we can have a look.
Thanks, I tried the modified script my work and the not work device.
The result with the new not working device:
exit code: 1, Traceback (most recent call last):
File "dlink2.py", line 4, in
Okay. So you get some object back but the object handler does not provide a lot of information. It is quite strange but the error message would suggest you get back non-ASCII chars. Try this,
if recursive or return_value is None:
_LOGGER.warning("Failed to open url to {}".format(self.ip))
self._error_report = True
return None
else:
return return_value
xmlData = response.read().decode('utf-8') # <---- Edit here
print(xmlData) # <---- and here
root = ET.fromstring(xmlData)
exit code: 1, Traceback (most recent call last):
File "dlink2.py", line 4, in
Still strange. So now the decode works... How about his,
if recursive or return_value is None:
_LOGGER.warning("Failed to open url to {}".format(self.ip))
self._error_report = True
return None
else:
return return_value
xmlData = response.read().decode('utf-8')
print(xmlData.encode('utf-8'))
root = ET.fromstring(xmlData)
"exit code: 1, Traceback (most recent call last):↵ File "dlink2.py", line 4, in
Okay.. so the error is moving down 😄
You only get the error? Not the print? Would really like to see the content of xmlData.
One final suggestion (a bit of going over the bridge but let's see),
xmlData = response.read().decode('utf-8')
print(xmlData.encode('utf-8'))
root = ET.fromstring(xmlData.encode('utf-8'))
It is alive!!!!!! :D Thank you very much. Now your script can work with DSP-W215 H/W Ver.:B2! :)
That great! Perhaps we can clean it up a bit then I can add it to the master branch. Can you check if this works,
try:
xmlData = response.read().decode()
except UnicodeEncodeError:
xmlData = response.read()
root = ET.fromstring(xmlData)
If is say something like: UnicodeEncodeError not defined then try,
try:
xmlData = response.read().decode()
except:
xmlData = response.read()
root = ET.fromstring(xmlData)
First version:
exit code: 1, Traceback (most recent call last):
File "dlink2.py", line 2, in
Second version:
exit code: 1, Traceback (most recent call last):
File "dlink2.py", line 2, in
Sorry. My bad. All the lines should be the same indentation (align). So I think the line with except needs a space?
No, no, my bad, I missec to write try. :D
First version:
exit code: 1, Traceback (most recent call last):
File "dlink2.py", line 4, in
Second version:
exit code: 1, Traceback (most recent call last):
File "dlink2.py", line 2, in
Okay.. Version 2 should work but is not aligned with the other lines. Perhaps it is missing a space or has one too many?
If the lines aligned like this: try: xmlData = response.read().decode() except: xmlData = response.read() root = ET.fromstring(xmlData)
Then:
exit code: 1, Traceback (most recent call last):
File "dlink2.py", line 4, in
It removed my tabs. :( try: xmlData = response.read().decode() except: xmlData = response.read() root = ET.fromstring(xmlData)
Edit: and my spaces...
Think I lost the overview of what your code looks like now 😄
In Python spaces are part of the language. So you normally use 4 space indentation. So the line after try should have four spaces more than try. The line after except should also have four spaces more than the except line. Try and except are indented by 8 spaces because they are part of the function that is part of a class. The class is zero spaces. All function below that start at 4 spaces. All code within a function starts at 8 spaces and so on.
I have added the number of spaces I have on each line to the beginning of the line,
8 try:
12 xmlData = response.read().decode()
8 except:
12 xmlData = response.read()
8 root = ET.fromstring(xmlData)
Does that make sense?
Hi, sorry for the late answer, but I killed my raspberry zero with a modbus test and tried to make it work again. I installed it with pip install pyW215 when use the command python dlink1.py (I have 2 dlinks and renamed the files to dlink1.py and dlink2.py) There is an error:
Traceback (most recent call last):
File "dlink1.py", line 2, in
I found the path where the pip installed the py: /home/pi/.local/lib/python2.7/site-packages/pyW215
There can be the problem?
Sorry for the late reply.
Try running which python
My guess is that you are running python3 but pip is installed on python2.7.
If that is the case you need to run python2.7 dlink1.py
Hi, now everything work like a charm. :) I did not modificate the pyW215.py file, only installed it with pip install pyW215.
You can close the issue. ;)
Hi, Your plugin works perfect with B1 version, but not with the B2 version. The firmware version is the same (2.22) with bth devices. I tried it with 2.23 with the same result. (Only with B2).
Can you help me how to solve this?
I get the following error message, (I removed the ip address and the key):
exit code: 1, Traceback (most recent call last): File "dlink2.py", line 4, in
sp = SmartPlug('xxx.xxx.xx.xx','xxxxxx')
File "/usr/local/lib/python2.7/dist-packages/pyW215/pyW215.py", line 61, in init
self.model_name = self.SOAPAction(Action="GetDeviceSettings", responseElement="ModelName", params = "")
File "/usr/local/lib/python2.7/dist-packages/pyW215/pyW215.py", line 168, in SOAPAction
xmlData = response.read().decode()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 383: ordinal not in range(128)