1

I am implementing Python client for Testrail in my project (http://docs.gurock.com/testrail-api2/bindings-python)

I am running an API call "get_test" and I am receiving an error as below

File "playground.py", line 10, in <module>
    case = client.send_get('get_test/53948')
  File "/Users/bhdev/Work/Python/TBH/testrail.py", line 36, in send_get
    return self.__send_request('GET', uri, None)
  File "/Users/bhdev/Work/Python/TBH/testrail.py", line 70, in __send_request
    response = urllib.request.urlopen(request).read()
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 526, in open
    response = self._open(req, data)
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 544, in _open
    '_open', req)
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1361, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1320, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)>

My code

from testrail import *


client = APIClient('https://******')
client.user = '*****'
client.password = '******'

case = client.send_get('get_test/xxxx')

print(case)

How could I bypass the SSL cert issue.

Thanks

slysid
  • 5,236
  • 7
  • 36
  • 59
  • Try `client.send_get('get_test/xxxx', verify=False)` – Itay4 Apr 18 '18 at 15:52
  • Already tried that, but verify is not recognized by the server as a valid param. I switched to requests and forming my own API requests against testrail – slysid Apr 18 '18 at 17:57
  • You cannot add an extra parameter to `client.send_get()` as it only accepts the one parameter - the uri. Internally, that calls through to `__send_request()`. See my full answer below. – testworks Apr 27 '18 at 03:19

2 Answers2

1

The root cause of your error is that the machine you are running the request on does not trust the certificate your TestRail server is using.

You can either:

  • Fix the SSL Certificate on your TestRail server
  • Modify the bindings (testrail.py) to disable certificate verification as per the instructions in PEP 476 :: Opting Out

Based on the current python bindings source code on github, you should be able to disable certificate verification as follows:

  • Change import json, base64 (line 14) to import json, base64, ssl
  • Add the following line to the __init__(self, base_url) method

self.context = ssl._create_unverified_context()

  • Modify the following line:

response = urllib.request.urlopen(request).read()

to pass in the unverified context.

response = urllib.request.urlopen(request, context=self.context).read()

testworks
  • 386
  • 1
  • 10
0

This addition solve me the problem in my case:

import ssl
ssl._create_default_https_context = ssl._create_unverified_context