# API behaviour differs depending upon Python version

**URL:** <https://forum.ansible.com/t/api-behaviour-differs-depending-upon-python-version/34672>\
**Category:** Ansible Developer\
**Created:** [February 23, 2021, 1:32pm UTC](https://forum.ansible.com/t/api-behaviour-differs-depending-upon-python-version/34672 "2021-02-23T13:32:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ceri\_Williams](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@Ceri\_Williams](https://forum.ansible.com/u/Ceri_Williams)\
**Post date:** [February 23, 2021, 1:32pm UTC](https://forum.ansible.com/t/api-behaviour-differs-depending-upon-python-version/34672/1 "2021-02-23T13:32:00Z")

</div>

Hi,

I am hoping that someone can explain a difference in behaviour when using the API, where success is achieved when using Python 2 (2.7 tested) and a failure occurs when using Python 3 (3.6 and 3.8 tested).

The outcome of running the same code with the 2 versions of Python are as follows (ansible == latest, but occurs on 2.9, 2.10 etc):

**Python 2.7**

./py2/bin/python test.py; echo $? → 0

# extract of full output

controller1 | SUCCESS =\> {  
“msg”: “a0492524b4da454d992d9987481cacf2”  
}  
node1 | SUCCESS =\> {  
“msg”: “a0492524b4da454d992d9987481cacf2”  
}

Ignore the fact that the machine ID is identical, as that is purely due to instances running from the same base image.

**Python 3.6**

./py3/bin/python test.py; echo $? → 2

# extract of full output

[WARNING]: Unhandled error in Python interpreter discovery for host node1: ‘\>’ not supported between instances of ‘NoneType’ and ‘int’  
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: ‘\>’ not supported between instances of ‘NoneType’ and ‘int’  
node1 | FAILED! =\> {  
“msg”: “Unexpected failure during module execution.”,  
“stdout”: “”  
}

controller1 | SUCCESS =\> {  
“msg”: “a0492524b4da454d992d9987481cacf2”  
}

I have attached the steps to reproduce the issue.

It seems to relate to the connection plugin, whereby unless a local connection is used then running with Python 3 will error, whereas Python 2 will not.

Cheers,

Ceri

> **(attachments)**
>
> [ansible-api-test.txt](https://forum.ansible.com/uploads/short-url/A0Kj9TKEEPibVQXIUZ7PGekTL3T.txt) (2.51 KB)
