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

Using send_post in Python


Hi everybody,

I try to send a request from python to testrail. In a simple case, that works fine.

But, I try to send a request created with my python code.

Example 1: This example do not work
My code is below:
d = {‘status_id’: 2, ‘comment’: ‘Updated automatically’, “custom_step_results”: [{“content”: “STEP 1”,“actual”: “step 1 OK blabla”,“status_id”: 1}]}

result = client.send_post(

I have testrail.APIError: TestRail API returned HTTP 400 (“Invalid or incomplete JSON string in API request.”)

Example 2: This example works fine:
result = client.send_post(
{‘status_id’: 2, ‘comment’: ‘Updated automatically’, “custom_step_results”: [{“content”: “STEP 1”,“actual”: “step 1 OK blabla”,“status_id”: 1}]}

Can you help me ? Perhaps, a problem with JSON manipulation or encoding (UTF8).

Thanks for you help !



I think, I don’t need data=json.dumps(d). But, I would like to create my request. And, I tried to work on string.

For example, I would like to replace STATUS by my value (2 for example). I have declared my string like that

d="{‘status_id’:STATUS, ‘comment’: ‘Updated automatically’}"
d= d.replace(STATUS, 2)
If I send this request, I have an error.

What are the good practices to use the POST in python ?



Hi Greg,

Thanks for your posting. You don’t need to do the JSON encoding yourself and this is handled transparently by the binding. You can pass structured Python objects instead and you can find a send_post here:



Hi Tobias,

Thank you for your quick response. It is ok for the JSON encoding.

But, can you explain me or give me some examples about structured Python objects ?

In fact, I would like to create my resquest to update each status of each steps. So, I need build this request from result.txt where each lines is a step:
Step 1 Passed: explanations
Step 2 Failed: explanations



Hi Greg,

Sure, happy to help. Do you use the separated steps field for this in TestRail? This expects a list of steps, each with the steps content and optionally status, expected and actual result. The raw JSON format looks as follows:

(see “Request Example”)

In Python, you would simply use a mix of Lists and Dictionaries to implement this and then pass this to send_post:



Yes, I would like to use the steps content.

With your documentation about list and dictionaries, I will try to read and create my request.

Thanks a lot Tobias,


Thanks, Greg, that sounds good. Just let me know in case any questions come up, happy to help :slight_smile: