Skip to content

Commit 49d7c3d

Browse files
author
Shakeel Mohamed
committed
Release 1.3.1
2 parents e3413fd + f0f2b0d commit 49d7c3d

File tree

9 files changed

+47
-10
lines changed

9 files changed

+47
-10
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*coverage_html_report*
66
.coverage
77
.coverage.*
8+
.python-version
89
__stdout__
910
docs/_build
1011
build/
@@ -18,4 +19,5 @@ examples/*/metadata
1819
tests/searchcommands_data/log/
1920
tests/searchcommands_data/output/
2021
examples/searchcommands_app/searchcommand_app.log
21-
Test Results*.html
22+
Test Results*.html
23+
tests/searchcommands/data/app/app.log

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Splunk SDK for Python Changelog
22

3+
## Version 1.3.1
4+
5+
### Bug fixes
6+
7+
* Hot fix to `binding.py` to work with Python 2.7.9, which introduced SSL certificate validation by default as outlined in [PEP 476](https://www.python.org/dev/peps/pep-0476).
8+
* Update `async`, `handler_proxy`, and `handler_urllib2` examples to work with Python 2.7.9 by disabling SSL certificate validation by default.
39

410
## Version 1.3.0
511

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The Splunk Software Development Kit for Python
22

3-
#### Version 1.3.0
3+
#### Version 1.3.1
44

55
The Splunk Software Development Kit (SDK) for Python contains library code and
66
examples designed to enable developers to build applications using Splunk.

examples/async/async.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import sys, os, datetime
2424
import urllib
25+
import ssl
2526
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", ".."))
2627

2728
import splunklib.binding as binding
@@ -171,7 +172,12 @@ def request(url, message, **kwargs):
171172
method = message.get("method", "GET")
172173

173174
# Note that we do not support proxies in this example
174-
opener = urllib2.build_opener()
175+
# If running Python 2.7.9+, disable SSL certificate validation
176+
if sys.version_info >= (2, 7, 9):
177+
unverified_ssl_handler = urllib2.HTTPSHandler(context=ssl._create_unverified_context())
178+
opener = urllib2.build_opener(unverified_ssl_handler)
179+
else:
180+
opener = urllib2.build_opener()
175181

176182
# Unfortunately, we need to use the hack of
177183
# "overriding" `request.get_method` to specify

examples/handlers/handler_proxy.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from pprint import pprint
3030
from StringIO import StringIO
3131
import sys, os
32+
import ssl
3233
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", ".."))
3334
import urllib2
3435

@@ -52,9 +53,15 @@ def request(url, message, **kwargs):
5253
method = message['method'].lower()
5354
data = message.get('body', "") if method == 'post' else None
5455
headers = dict(message.get('headers', []))
55-
context = urllib2.Request(url, data, headers)
56+
req = urllib2.Request(url, data, headers)
5657
try:
57-
response = urllib2.urlopen(context)
58+
response = urllib2.urlopen(req)
59+
except urllib2.URLError, response:
60+
# If running Python 2.7.9+, disable SSL certificate validation and try again
61+
if sys.version_info >= (2, 7, 9):
62+
response = urllib2.urlopen(req, context=ssl._create_unverified_context())
63+
else:
64+
raise
5865
except urllib2.HTTPError, response:
5966
pass # Propagate HTTP errors via the returned response message
6067
return {

examples/handlers/handler_urllib2.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import sys, os
2222
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", ".."))
2323
import urllib2
24+
import ssl
2425

2526
import splunklib.client as client
2627

@@ -34,9 +35,13 @@ def request(url, message, **kwargs):
3435
method = message['method'].lower()
3536
data = message.get('body', "") if method == 'post' else None
3637
headers = dict(message.get('headers', []))
37-
context = urllib2.Request(url, data, headers)
38+
# If running Python 2.7.9+, disable SSL certificate validation
39+
req = urllib2.Request(url, data, headers)
3840
try:
39-
response = urllib2.urlopen(context)
41+
if sys.version_info >= (2, 7, 9):
42+
response = urllib2.urlopen(req, context=ssl._create_unverified_context())
43+
else:
44+
response = urllib2.urlopen(req)
4045
except urllib2.HTTPError, response:
4146
pass # Propagate HTTP errors via the returned response message
4247
return {

splunklib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414

1515
"""Python library for Splunk."""
1616

17-
__version_info__ = (1, 3, 0)
17+
__version_info__ = (1, 3, 1)
1818
__version__ = ".".join(map(str, __version_info__))
1919

splunklib/binding.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import ssl
3131
import urllib
3232
import io
33+
import sys
3334

3435
from datetime import datetime
3536
from functools import wraps
@@ -1204,6 +1205,10 @@ def connect(scheme, host, port):
12041205
if scheme == "https":
12051206
if key_file is not None: kwargs['key_file'] = key_file
12061207
if cert_file is not None: kwargs['cert_file'] = cert_file
1208+
1209+
# If running Python 2.7.9+, disable SSL certificate validation
1210+
if sys.version_info >= (2,7,9) and key_file is None and cert_file is None:
1211+
kwargs['context'] = ssl._create_unverified_context()
12071212
return httplib.HTTPSConnection(host, port, **kwargs)
12081213
raise ValueError("unsupported scheme: %s" % scheme)
12091214

tests/test_binding.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import testlib
2525
import unittest
2626
import socket
27+
import sys
28+
import ssl
2729

2830
import splunklib.binding as binding
2931
from splunklib.binding import HTTPError, AuthenticationError, UrlEncoded
@@ -428,9 +430,13 @@ def urllib2_handler(url, message, **kwargs):
428430
method = message['method'].lower()
429431
data = message.get('body', "") if method == 'post' else None
430432
headers = dict(message.get('headers', []))
431-
context = urllib2.Request(url, data, headers)
433+
req = urllib2.Request(url, data, headers)
432434
try:
433-
response = urllib2.urlopen(context)
435+
# If running Python 2.7.9+, disable SSL certificate validation
436+
if sys.version_info >= (2, 7, 9):
437+
response = urllib2.urlopen(req, context=ssl._create_unverified_context())
438+
else:
439+
response = urllib2.urlopen(req)
434440
except urllib2.HTTPError, response:
435441
pass # Propagate HTTP errors via the returned response message
436442
return {

0 commit comments

Comments
 (0)