Skip to content

Commit

Permalink
gist.py - handle older pythons where we can't disable ssl verification
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Apr 15, 2015
1 parent bd429ad commit cc2739f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion gist.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
2015-02-05 jantman:
- initial script
2015-04-15 jantman:
- catch error on ssl import and disable no_verify option
"""

import httplib
Expand All @@ -32,12 +35,18 @@
import json
import logging
from copy import deepcopy
from ssl import _create_unverified_context

FORMAT = "[%(levelname)s %(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s"
logging.basicConfig(level=logging.ERROR, format=FORMAT)
logger = logging.getLogger(__name__)

try:
from ssl import _create_unverified_context
have_ssl = True
except ImportError:
logger.error("ERROR - could not import ssl._create_unverified_context; unable to disable SSL cert verification")
have_ssl = False

def debug_response(response):
logger.debug("Response status {s}".format(s=response.status))
logger.debug("Response: {d}".format(d=response.read()))
Expand Down Expand Up @@ -115,6 +124,10 @@ def gist_write(name, content, token=None, prefix=False, no_verify=False):
if options.verbose:
logger.setLevel(logging.DEBUG)

if options.no_verify and not have_ssl:
logger.error("ERROR: could not import ssl._create_unverified_context; therefore unable to disable SSL cert verification")
raise SystemExit(1)

if len(args) < 1:
sys.stderr.write(usage + "\n")
raise SystemExit(1)
Expand Down

0 comments on commit cc2739f

Please sign in to comment.