# python api return code. when task fails

**URL:** <https://forum.ansible.com/t/python-api-return-code-when-task-fails/35402>\
**Category:** Ansible Developer\
**Created:** [June 24, 2021, 2:00pm UTC](https://forum.ansible.com/t/python-api-return-code-when-task-fails/35402 "2021-06-24T14:00:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mario\_Garcia](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@Mario\_Garcia](https://forum.ansible.com/u/Mario_Garcia)\
**Post date:** [June 24, 2021, 2:00pm UTC](https://forum.ansible.com/t/python-api-return-code-when-task-fails/35402/1 "2021-06-24T14:00:14Z")

</div>

I am running the python api to develop an inhouse script but the script returns always 0 even if a task failed. how can we capture the task exit code.?

the python script always returns 0 even per instance there is a copy tasks that failed to validate. i get on stdout that the task failed however the rc code of the script is still 0!

I am using this example to copy a file to remote hosts it works fine but not when the copy is unsuccessful…  
[https://docs.ansible.com/ansible/2.9/dev\_guide/developing\_api.html](https://docs.ansible.com/ansible/2.9/dev_guide/developing_api.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 24, 2021, 2:10pm UTC](https://forum.ansible.com/t/python-api-return-code-when-task-fails/35402/2 "2021-06-24T14:10:53Z")

</div>

tasks do not use return codes, their status is reflected in the return  
data dictionary as keys.
