feat(SSL): Support to disable SSL certificate verification · watson-developer-cloud/python-sdk@e0f1d11

3 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -25,6 +25,7 @@ Python client library to quickly get started with the various [Watson APIs][wdc]

2525

* [Changes for v2.0](#changes-for-v20)

2626

* [Migration](#migration)

2727

* [Configuring the http client](#configuring-the-http-client-supported-from-v110)

28+

* [Disable SSL certificate verification](#disable-ssl-certificate-verification)

2829

* [Sending request headers](#sending-request-headers)

2930

* [Parsing HTTP response info](#parsing-http-response-info)

3031

* [Dependencies](#dependencies)

@@ -203,6 +204,13 @@ response = assistant.message(workspace_id=workspace_id, input={

203204

print(json.dumps(response, indent=2))

204205

```

205206
207+

## Disable SSL certificate verification

208+

For ICP(IBM Cloud Private), you can disable the SSL certificate verification by:

209+
210+

```python

211+

service.disable_SSL_verification()

212+

```

213+
206214

## Sending request headers

207215

Custom headers can be passed in any request in the form of a `dict` as:

208216

```python

Original file line numberDiff line numberDiff line change

@@ -163,3 +163,11 @@ def test_for_icp():

163163

assert service2.username is not None

164164

assert service2.password is not None

165165

assert service2.url is 'service_url'

166+
167+

@responses.activate

168+

def test_disable_SSL_verification():

169+

service1 = AnyServiceV1('2017-07-07', api_key='icp-xxxx', url='service_url')

170+

assert service1.verify is None

171+
172+

service1.disable_SSL_verification()

173+

assert service1.verify is False

Original file line numberDiff line numberDiff line change

@@ -233,6 +233,7 @@ def __init__(self, vcap_services_name, url, username=None, password=None,

233233

self.iam_access_token = None

234234

self.iam_url = None

235235

self.token_manager = None

236+

self.verify = None # Indicates whether to ignore verifying the SSL certification

236237
237238

user_agent_string = 'watson-apis-python-sdk-' + __version__ # SDK version

238239

user_agent_string += ' ' + platform.system() # OS

@@ -349,6 +350,9 @@ def set_http_config(self, http_config):

349350

else:

350351

raise TypeError("http_config parameter must be a dictionary")

351352
353+

def disable_SSL_verification(self):

354+

self.verify = False

355+
352356

def set_detailed_response(self, detailed_response):

353357

self.detailed_response = detailed_response

354358

@@ -445,6 +449,10 @@ def request(self, method, url, accept_json=False, headers=None,

445449

params['api_key'] = self.api_key

446450
447451

kwargs = dict(kwargs, **self.http_config)

452+
453+

if self.verify is not None:

454+

kwargs['verify'] = self.verify

455+
448456

response = requests.request(method=method, url=full_url,

449457

cookies=self.jar, auth=auth,

450458

headers=headers,