Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket connection failure for realtime data #30

Open
elijah286 opened this issue Apr 2, 2019 · 4 comments
Open

Websocket connection failure for realtime data #30

elijah286 opened this issue Apr 2, 2019 · 4 comments

Comments

@elijah286
Copy link

I can connect and see historical data, but invoking update_realtime() returns this error: ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)

@kbickar
Copy link
Collaborator

kbickar commented Apr 8, 2019

Looks like you need certificates installed, this thread has some suggestions: https://stackoverflow.com/questions/50236117/scraping-ssl-certificate-verify-failed-error-for-http-en-wikipedia-org

@howartp84
Copy link

I had this last night.

MacOS Sierra uses OpenSSL 0.9.8 which is deprecated and doesn't support TLS 1.1 or TLS 1.2.

High Sierra and later uses LibreSSL, which fixed the problem when I upgraded OS.

@clarsen
Copy link

clarsen commented Jul 4, 2019

seen on Raspberry PI with Python 3.7.3:

  File "poll.py", line 24, in <module>
    sense.update_realtime()
  File "/home/pi/.local/share/virtualenvs/home-energy-monitor-ttUzj-Xz/lib/python3.7/site-packages/sense_energy/senseable.py", line 43, in update_realtime
    next(self.get_realtime_stream())
  File "/home/pi/.local/share/virtualenvs/home-energy-monitor-ttUzj-Xz/lib/python3.7/site-packages/sense_energy/senseable.py", line 51, in get_realtime_stream
    ws = create_connection(url, timeout=self.wss_timeout)
  File "/home/pi/.local/share/virtualenvs/home-energy-monitor-ttUzj-Xz/lib/python3.7/site-packages/websocket/_core.py", line 514, in create_connection
    websock.connect(url, **options)
  File "/home/pi/.local/share/virtualenvs/home-energy-monitor-ttUzj-Xz/lib/python3.7/site-packages/websocket/_core.py", line 223, in connect
    options.pop('socket', None))
  File "/home/pi/.local/share/virtualenvs/home-energy-monitor-ttUzj-Xz/lib/python3.7/site-packages/websocket/_http.py", line 126, in connect
    sock = _ssl_socket(sock, options.sslopt, hostname)
  File "/home/pi/.local/share/virtualenvs/home-energy-monitor-ttUzj-Xz/lib/python3.7/site-packages/websocket/_http.py", line 260, in _ssl_socket
    sock = _wrap_sni_socket(sock, sslopt, hostname, check_hostname)
  File "/home/pi/.local/share/virtualenvs/home-energy-monitor-ttUzj-Xz/lib/python3.7/site-packages/websocket/_http.py", line 239, in _wrap_sni_socket
    server_hostname=hostname,
  File "/usr/lib/python3.7/ssl.py", line 412, in wrap_socket
    session=session
  File "/usr/lib/python3.7/ssl.py", line 853, in _create
    self.do_handshake()
  File "/usr/lib/python3.7/ssl.py", line 1117, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: WRONG_SIGNATURE_TYPE] wrong signature type (_ssl.c:1056)

@clarsen
Copy link

clarsen commented Jul 4, 2019

referring to this 'fix': https://github.com/kennethreitz/requests/issues/4775#issuecomment-478198879

and ability to set this within the websocket connection code:
https://github.com/websocket-client/websocket-client/blob/1c2219b8a580182db63e9ae1ed3cc1d58f25845b/websocket/_http.py#L227

In sense_energy/senseable.py:

-            ws = create_connection(url, timeout=self.wss_timeout)
+            ws = create_connection(url, timeout=self.wss_timeout, sslopt={'ciphers': 'DEFAULT@SECLEVEL=1'})

Setting 'ciphers' for sslopt 'fixes' it, but I'd be cautious about patching this in anything more than a non-production use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants