Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.

[API][Python] Initial setup, help needed


Hi all,

I’m having some difficulty setting up the basic API test with Python. I may be missing something obvious, but I’d thought I’d post on here in case the result helps somebody else…

I’m running with Python 3.4, located “C:\Python34”.
I’ve downloaded the Python TestRail API bindings ( and have extracted “testrail-api-master\python\3.x\” to “C:\Python34”.

I’ve taken the following example from ( and saved it as “” in “C:\Python\Tests”

[code]from testrail import *

client = APIClient(‘http:///testrail/’)
client.user = ''
client.password = ''
case = client.send_get(‘get_case/1’)

… With the URL, Password and Username replaced and relevant to my installation, when I attempt to execute “” in cmd the following error is returned. Any ideas why?

C:\Python34\Tests> Traceback (most recent call last): File "C:\Python34\Tests\", line 6, in <module> case = client.send_get('get_case/1') File "C:\Python34\", line 36, in send_get return self.__send_request('GET', uri, None) File "C:\Python34\", line 76, in __send_request result = json.loads(response.decode()) File "C:\Python34\lib\json\", line 318, in loads return _default_decoder.decode(s) File "C:\Python34\lib\json\", line 343, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Python34\lib\json\", line 361, in raw_decode raise ValueError(errmsg("Expecting value", s, err.value)) from None ValueError: Expecting value: line 1 column 1 (char 0)

(I have existing test cases which should be returned)
(The user is active)
(API is enabled)


Hello Lloyd,

Thanks for your posting. Please make sure that the TestRail address is correct (it appears that your web server returns an unexpected or empty result). Do you use a local TestRail server or a TestRail instance on our server (



Hi Tobias,

We are locally installed. The web address is definitely correct.

I checked Admin > System log and I was receiving the following messages:

[code][AuthException] Authentication failed: invalid or missing user/password or session cookie.

File: C:\inetpub\wwwroot\testrail\sys\helpers\ex.php
Line: 25
Status Code: 500
Uri: /index.php?/api/v2/get_case/1 (GET)

Browser: Python-urllib/3.4
PHP: 5.4.24

at ex::raise (ex.php:25)
at ex::raise (ex.php:77)
at ex::raiset (v2.php:128)
at V2_controller->_check_user (v2.php:16)
at V2_controller->_init (gizmo.php:100)
at require_once (index.php:106)[/code]

… It turns out by a complete oversight :rolleyes: I was incorrectly using the username as opposed to the user email address (In the ‘client.user =’ line)

I’m now getting the desired result. Sorry for wasting time!


Hello Lloyd,

Thanks for your reply and great to hear that it works now :slight_smile:

We will make sure to review this on our side as well as you should see an authentication exception/error instead of a JSON error. Thanks again for reporting this and please let me know in case any questions come while learning/using the API.