From f85761575f7c341b6f1bf711e1885f623f70637f Mon Sep 17 00:00:00 2001 From: Olivier Janin Date: Wed, 30 Sep 2020 15:05:46 +0200 Subject: [PATCH] Add option to use unsecure ssl connexion --- python/2.x/testrail.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/python/2.x/testrail.py b/python/2.x/testrail.py index eb35a7d..b0d7068 100644 --- a/python/2.x/testrail.py +++ b/python/2.x/testrail.py @@ -22,6 +22,7 @@ class APIClient: def __init__(self, base_url): self.user = '' self.password = '' + self.ssl_secure = True if not base_url.endswith('/'): base_url += '/' self.__url = base_url + 'index.php?/api/v2/' @@ -56,21 +57,24 @@ def send_post(self, uri, data): def __send_request(self, method, uri, data): url = self.__url + uri + if not self.ssl_secure: + requests.packages.urllib3.disable_warnings() + auth = base64.b64encode('%s:%s' % (self.user, self.password)) headers = {'Authorization': 'Basic ' + auth} if method == 'POST': if uri[:14] == 'add_attachment': # add_attachment API method files = {'attachment': (open(data, 'rb'))} - response = requests.post(url, headers=headers, files=files) + response = requests.post(url, headers=headers, files=files, verify=self.ssl_secure) files['attachment'].close() else: headers['Content-Type'] = 'application/json' payload = bytes(json.dumps(data)) - response = requests.post(url, headers=headers, data=payload) + response = requests.post(url, headers=headers, data=payload, verify=self.ssl_secure) else: headers['Content-Type'] = 'application/json' - response = requests.get(url, headers=headers) + response = requests.get(url, headers=headers, verify=self.ssl_secure) if response.status_code > 201: try: