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

SSL Certificate Verification failed - Firmware 1.19.0 #5

Open
h0lyc0w opened this issue Jun 20, 2018 · 21 comments
Open

SSL Certificate Verification failed - Firmware 1.19.0 #5

h0lyc0w opened this issue Jun 20, 2018 · 21 comments

Comments

@h0lyc0w
Copy link

h0lyc0w commented Jun 20, 2018

My powerwall2 was recently upgraded to firmware 1.19.0. After the upgrade, Powerwall2PVOutput could no longer export data from my PW2 due to SSL issues. Here's the error message:

2018-06-19 23:15:42,334 - getPowerwallData: [Errno socket error] [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)

I managed to get it working again by using the following environment variable to disable the HTTPS verification check before running PW_DataLogger and PW_PVOExport:
PYTHONHTTPSVERIFY=0

It's a work around for now.

@ekul135
Copy link
Owner

ekul135 commented Jul 5, 2018

What O/S do you get this error on?

@h0lyc0w
Copy link
Author

h0lyc0w commented Jul 5, 2018

Linux raspberrypi 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017 armv7l
Python 2.7.13

@ekul135
Copy link
Owner

ekul135 commented Jul 5, 2018

I've seen the error firsthand on another O/S. Have you tried sudo apt-get update && sudo apt-get install ca-certificates

@ekul135
Copy link
Owner

ekul135 commented Jul 5, 2018

The issue really isn't a big one, as you said PYTHONHTTPSVERIFY=0 does work, however it's a bit of a hack and would rather sort this out properly. It's not really an issue with this code, rather an issue with ensuring the correct certificates are installed.

@h0lyc0w
Copy link
Author

h0lyc0w commented Jul 6, 2018

True, it's not an issue with the code. I just wanted to let you know it was encountered and a there's a workaround. The "fix" would be to add the self-signed certificate used by the gateway to the OS trusted datastore. I may do that, but since it's working, I'm ok with leaving as is.

Another option might be adding a "no verify" option to the config to ignore the certificate; similar to the environment variable workaround.

@ekul135
Copy link
Owner

ekul135 commented Jul 6, 2018

Thanks for your help h0lyc0w will leave this issue open

@zzatihz1
Copy link

Argh! My Powerwall firmware was updated to 1.2 last night and now the download of data is failing. I'm not a Python programmer and am struggling to see where I can set the PYTHONHTTPSVERIFY=0 setting. Is this part of the Linux environment variables? Is this something that can be set when the Python script is invoked as part of the command line?

Thanks in advance for any help.

@zzatihz1
Copy link

Success! I tried the environment variable method and could not get it to work. But I was able to add the following code to the data logger script which does work! Thanks to http://blog.pengyifan.com/how-to-fix-python-ssl-certificate_verify_failed/ for the solution.

import os, ssl
if (not os.environ.get('PYTHONHTTPSVERIFY', '') and
getattr(ssl, '_create_unverified_context', None)):
ssl._create_default_https_context = ssl._create_unverified_context

@zzatihz1
Copy link

Spoke too soon. Still not working. I had one successful read and now it's failing again.

@zzatihz1
Copy link

I'm cautiously optimistic that it is working again. I rebooted my Raspberry Pi and the scripts seem to be working and uploading data to PVOutput. There is a lot of discussion on https://teslamotorsclub.com/tmc/threads/firmware-1-20-0.121634/ regarding the latest Powerwall 2 v1.20 firmware update. Many users have been complaining that Tesla is disabling API access for some owners.

@icepicknz
Copy link

I just got 1.20 and its requiring SSL, is there any update to the logger etc?

@ekul135
Copy link
Owner

ekul135 commented Jul 17, 2018

In PW_Helper, change your http references to https

Then change the way you are calling the python script by inserting "PYTHONHTTPSVERIFY=0".

e.g. PYTHONHTTPSVERIFY=0 python your_script

@icepicknz
Copy link

I edited the URL's already and also tried that...

root@piaware-dayna:~/Powerwall2PVOutput-master# PYTHONHTTPSVERIFY=0 python /root/Powerwall2PVOutput-master/PW_Datalogger.py
2018-07-17 03:30:59,984 - Start PVOutput datalogger
2018-07-17 03:31:00,031 - getPowerwallData: [Errno socket error] [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)
2018-07-17 03:31:00,051 - getPowerwallSOCData: [Errno socket error] [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)
2018-07-17 03:31:00,052 - No data received, retrying
2018-07-17 03:31:05,089 - getPowerwallData: [Errno socket error] [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)
2018-07-17 03:31:05,109 - getPowerwallSOCData: [Errno socket error] [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)
2018-07-17 03:31:05,110 - No data received, retrying

root@piaware-dayna:/Powerwall2PVOutput-master# python --version
Python 2.7.9
root@piaware-dayna:
/Powerwall2PVOutput-master#

@ekul135
Copy link
Owner

ekul135 commented Jul 17, 2018

have you tried the other work around above? In the datalogger file:

import os, ssl
if (not os.environ.get('PYTHONHTTPSVERIFY', '') and
getattr(ssl, '_create_unverified_context', None)):
ssl._create_default_https_context = ssl._create_unverified_context

@icepicknz
Copy link

Yeah i did :/ just looking what else i can do now :(

@ekul135
Copy link
Owner

ekul135 commented Jul 17, 2018

Can you hit the web interface?

@icepicknz
Copy link

Yup and i can use curl -sk and get results fine too

@ekul135
Copy link
Owner

ekul135 commented Jul 17, 2018

@zzatihz1 did you get this running on 1.20, I don't have access to that specific firmware to debug.

I have 1.19 working with PYTHONHTTPSVERIFY=0.

@icepicknz
Copy link

Can you private message me (don't know how lol) and i can provide a temporary pinhole to my power wall if you wish

@zzatihz1
Copy link

@ekul135 The modification I made was to the datalogger script based on what I shared from http://blog.pengyifan.com/how-to-fix-python-ssl-certificate_verify_failed/ . Setting PYTHONHTTPSVERIFY=0 did not work for me. I have confirmed that my Powerwall is on v1.20.0. As of this morning, the script continues to work well posting to the database and uploading to PVOutput as designed.

@jackkorber
Copy link

My powerwalls were updated to 1.20 and I am using the PYTHONHTTPSVERIFY=0 in crontab without issues.

������������������������������������������������������������������������������������������������������* * * * * sudo PYTHONHTTPSVERIFY=0 /usr/bin/python /home/pi/path/script.py >/home/pi/path/script.txt 2>&1�

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

5 participants