diff options
author | Lukas Fleischer <lfleischer@calcurse.org> | 2016-01-23 08:22:23 +0100 |
---|---|---|
committer | Lukas Fleischer <lfleischer@calcurse.org> | 2016-01-23 08:22:49 +0100 |
commit | dcdc79217822adc4311b787aed1c7adabebf3325 (patch) | |
tree | 5df493dc1bd1d00785b0aa0763dd712641732ab5 | |
parent | d516a8ff873f2b72c856d44e57356913e50d9922 (diff) | |
download | calcurse-dcdc79217822adc4311b787aed1c7adabebf3325.zip |
calcurse-caldav: Add a workaround for Python <3.4
Python versions prior to 3.4 do not check certificates by default and
thus do not support ssl._create_unverified_context(). Add a workaround.
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
-rwxr-xr-x | contrib/caldav/calcurse-caldav.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/contrib/caldav/calcurse-caldav.py b/contrib/caldav/calcurse-caldav.py index 94d1775..edd50d8 100755 --- a/contrib/caldav/calcurse-caldav.py +++ b/contrib/caldav/calcurse-caldav.py @@ -385,12 +385,19 @@ open(lockfn, 'w') try: # Connect to the server via HTTPs. if insecure_ssl: - context = ssl._create_unverified_context() + try: + context = ssl._create_unverified_context() + conn = http.client.HTTPSConnection(hostname, context=context) + except AttributeError: + # Python versions prior to 3.4 do not support + # ssl._create_unverified_context(). However, these versions do not + # seem to verify certificates by default so we can simply fall back + # to http.client.HTTPSConnection(). + conn = http.client.HTTPSConnection(hostname) else: - context = ssl._create_default_https_context() + conn = http.client.HTTPSConnection(hostname) if verbose: print('Connecting to ' + hostname + '...') - conn = http.client.HTTPSConnection(hostname, context=context) if init: # In initialization mode, start with an empty synchronization database. |