lucien2k / sonoff-python

Make use of your sonoff smart switches without flashing them via the cloud APIs
MIT License
51 stars 32 forks source link

An empty list returns by method get_devices() #14

Closed VDigitall closed 4 years ago

VDigitall commented 4 years ago

An empty list returns by method get_devices() I found that response from server in method update_devices() return {"error":400,"msg":"params incomplete"}

Fix: https://github.com/lucien2k/sonoff-python/pull/13

estebanroblesluna commented 4 years ago

Verified! Thanks @VDigitall for sharing! Having a SSL issue now

VDigitall commented 4 years ago

Can you provide more information?

estebanroblesluna commented 4 years ago

Sure, I have 2 sonoff basics. and I'm running:

s = Sonoff("xxx, "yyy", "us") devices = s.get_devices() if devices:

We found a device, lets turn something on

device_id = devices[0]['deviceid']
s.switch('on', device_id, None)
time.sleep(10)
s.switch('off', device_id, None)

This is the stack trace:

/Users/estebanroblesluna/anaconda2/envs/please-smile2/bin/python /Users/estebanroblesluna/disk/code/ps/please-smile/test/sonoff_test.py Traceback (most recent call last): File "/Users/estebanroblesluna/disk/code/ps/please-smile/test/sonoff_test.py", line 10, in s.switch('on', device_id, None) File "/Users/estebanroblesluna/disk/code/ps/please-smile/services/v2/switch/SonoffLib.py", line 255, in switch self._ws = self._get_ws() File "/Users/estebanroblesluna/disk/code/ps/please-smile/services/v2/switch/SonoffLib.py", line 220, in _get_ws self._ws = create_connection(('wss://{}:8080/api/ws'.format(self._wshost)), timeout=10) File "/Users/estebanroblesluna/anaconda2/envs/please-smile2/lib/python2.7/site-packages/websocket/_core.py", line 511, in create_connection websock.connect(url, **options) File "/Users/estebanroblesluna/anaconda2/envs/please-smile2/lib/python2.7/site-packages/websocket/_core.py", line 220, in connect options.pop('socket', None)) File "/Users/estebanroblesluna/anaconda2/envs/please-smile2/lib/python2.7/site-packages/websocket/_http.py", line 126, in connect sock = _ssl_socket(sock, options.sslopt, hostname) File "/Users/estebanroblesluna/anaconda2/envs/please-smile2/lib/python2.7/site-packages/websocket/_http.py", line 253, in _ssl_socket sock = _wrap_sni_socket(sock, sslopt, hostname, check_hostname) File "/Users/estebanroblesluna/anaconda2/envs/please-smile2/lib/python2.7/site-packages/websocket/_http.py", line 232, in _wrap_sni_socket server_hostname=hostname, File "/Users/estebanroblesluna/anaconda2/envs/please-smile2/lib/python2.7/ssl.py", line 369, in wrap_socket _context=self) File "/Users/estebanroblesluna/anaconda2/envs/please-smile2/lib/python2.7/ssl.py", line 599, in init self.do_handshake() File "/Users/estebanroblesluna/anaconda2/envs/please-smile2/lib/python2.7/ssl.py", line 828, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:727)

Process finished with exit code 1

lucien2k commented 4 years ago

This is probably a problem with either self-signed certs or expired certs.

export PYTHONHTTPSVERIFY=0

will work around it

estebanroblesluna commented 4 years ago

Thanks that works

arnaudelub commented 4 years ago

Hey, sorry to reopen the issue, but i'm having the same problem, returned device list is empty, i'm correctly connected. If i try the get request using my bearer_token and the params in your code i'm receiving {"error":400,"msg":"params incomplete"} Thanks for your help