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

Headers missing from .send_get (python) using example


Greetings. I was looking at 2.x python bindings for TestRail. Was attempting to just do the first send_get('get_case/1') example:

from testrail import *

client = APIClient(‘’)
client.user = '’
client.password = ‘helloWorld’

case = client.send_get(‘get_case/1/1’)
print case

This returns:

testrail.APIError: TestRail API returned HTTP 400 ("Content-Type header missing (use Content-Type: application/json)")

I haven’t made any modifications to the code. Using the Python 2.x bindings ‘out of the box’. Any help is appreciated.


Hey @joshtewing,

Try to change the client.send_get('get_case/1/1') to client.send_get('get_case/1')


Thanks, sadly to no avail.

Full URL:

I also added the following to __send_request:

def __send_request(self, method, uri, data):
    url = self.__url + uri
    request = urllib2.Request(url)
    if method == 'POST':

    auth = base64.b64encode('%s:%s' % (self.user, self.password))
    request.add_header('Authorization', 'Basic %s' % auth)
    request.add_header('Content-Type', 'application/json')
    print request.has_header('application/json')
    print request.get_header('Content-Type')
    print request.get_full_url()
    print request.get_method()

has_header returns False
get_header returns None
get_full_url returns
get_method returns GET


Just to double check you, in the admin page under site settings you have the API enabled and session authentication right?


Yes, they are both enabled. :confused:

Thank you for your replies. If I can’t get it working in the next couple minutes I’m just going to rewrite the bindings and open a pull request.


Hi Josh,

Thanks for your posting! The solution is simple and you would need to use HTTPS instead of HTTP:

client = APIClient('')

Using just HTTP would result in a redirect which in turn results in a new HTTP request and different headers and this would explain why TestRail doesn’t see your Content-Type or Authorization headers.

I hope this helps!



Thanks, Tobias. I had the same problem, adding the “s” worked :slight_smile:


Great to hear that, Sarah :slight_smile: