Skip to content

SSL CERTIFICATE_VERIFY_FAILED issue when connecting to websocket (switch on/off) #21

Open
@marcinlubojanski

Description

@marcinlubojanski

I was getting following error:
Traceback (most recent call last): File "./sonoff_test.py", line 12, in <module> s.switch('off', device_id, None) File "/opt/lib/python3.6/site-packages/sonoff/sonoff.py", line 255, in switch self._ws = self._get_ws() File "/opt/lib/python3.6/site-packages/sonoff/sonoff.py", line 219, in _get_ws self._ws = create_connection(('wss://{}:8080/api/ws'.format(self._wshost)), timeout=10) File "/opt/lib/python3.6/site-packages/websocket/_core.py", line 515, in create_connection websock.connect(url, **options) File "/opt/lib/python3.6/site-packages/websocket/_core.py", line 223, in connect options.pop('socket', None)) File "/opt/lib/python3.6/site-packages/websocket/_http.py", line 127, in connect sock = _ssl_socket(sock, options.sslopt, hostname) File "/opt/lib/python3.6/site-packages/websocket/_http.py", line 264, in _ssl_socket sock = _wrap_sni_socket(sock, sslopt, hostname, check_hostname) File "/opt/lib/python3.6/site-packages/websocket/_http.py", line 243, in _wrap_sni_socket server_hostname=hostname, File "/opt/lib/python2.7/ssl.py", line 363, in wrap_socket File "/opt/lib/python2.7/ssl.py", line 611, in __init__ File "/opt/lib/python2.7/ssl.py", line 840, in do_handshake ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] unknown error (_ssl.c:661)

I have fixed it by modifying _get_ws method.

instead of create_connection I use those 2 lines:
self._ws = websocket.WebSocket(sslopt={"cert_reqs": ssl.CERT_NONE}) self._ws.connect('wss://{}:8080/api/ws'.format(self._wshost)) #self._ws = create_connection(('wss://{}:8080/api/ws'.format(self._wshost)), timeout=10)

it requires also import ssl and import websocket

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions