# Multiple Arguments to Python Shell

**URL:** <https://discourse.nodered.org/t/multiple-arguments-to-python-shell/74239>\
**Category:** General\
**Tags:** python\
**Created:** [27 January 2023 00:51 UTC](https://discourse.nodered.org/t/multiple-arguments-to-python-shell/74239 "2023-01-27T00:51:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rauth](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@Rauth](https://discourse.nodered.org/u/Rauth)\
**Post date:** [27 January 2023 00:51 UTC](https://discourse.nodered.org/t/multiple-arguments-to-python-shell/74239/1 "2023-01-27T00:51:24Z")

</div>

Hello,

I'm a beginner on both JS and Python, so I can't get too deep into the weeds on the script side. Hopefully I can provide enough context so that my question makes sense.

I am trying to run a single pass python script (ReadObjectList.py from the Bacpypes library) that requires two arguments to execute. This is using the python shell node.

I can manually run the command on the host (Alpine Linux) with  
#python ReadObjectList.py \<device\_id\> \<device\_addr\>  
(both values entered with no punctuation, separated by a single space).  
It works perfectly from the host CLI.

In Node-Red, I can't find a way to satisfy both arguments, as the script is expecting an integer for the ID and a string for the address.  
If I send both arguments as a single string, the script doesn't accept it and errors out on invalid integer for device\_id.  
If I inject the ID as a number type, it skips past that error and of course comes back with an error for missing the address.

From what I've gathered, the value of msg.payload can't be of mixed types.

I've tried breaking the message up into an array, which does allow the two values to exist as different types, but if I inject that array into the python shell node, it errors out for both required arguments being missing and spits back the array as a string (square brackets included).

Does anyone know of a workaround or trick that would let me pass those two arguments on invoking the script? I'm not opposed to an exec node either, but it seems that the mixed data types is going to be an issue either way.

The python shell seems to work well with other scripts that take either a single argument or listen for console commands that can be injected in the msg.payload.

Thanks for reading!

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [27 January 2023 04:41 UTC](https://discourse.nodered.org/t/multiple-arguments-to-python-shell/74239/2 "2023-01-27T04:41:38Z")

</div>

How are you trying to execute this from node-red ? (ie. what does your flow look like)

Note that there is a [bacnet node for node-red](https://flows.nodered.org/node/node-red-contrib-bacnet) as well.

---

<div class="post-metadata">

**Author:** ![Rauth](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@Rauth](https://discourse.nodered.org/u/Rauth)\
**Post date:** [27 January 2023 05:53 UTC](https://discourse.nodered.org/t/multiple-arguments-to-python-shell/74239/3 "2023-01-27T05:53:29Z")

</div>

I've tried to use the Node-Red BACnet, but it doesn't support MS/TP devices. There is a new module out from Bitpool that also uses the JS Bacstack library and DOES detect the MS/TP devices but has issues properly fetching the objects.

The python Bacpypes library is much further developed, and the included samples so far have worked extremely well when running via CLI in the host. Network discovery works well in a Node-Red python shell, but that script runs and listens for singular arguments on the Std-In.

The script I'm trying to run requires the two arguments. It fires up, runs once, and closes when it gets the results.  
Here is a barebones flow of the nodes I'm working with.

```auto
[
    {
        "id": "63fb3651af578236",
        "type": "tab",
        "label": "Read Object List",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "21b26a2ea19de941",
        "type": "pythonshell in",
        "z": "63fb3651af578236",
        "name": "ReadObjectList.py",
        "pyfile": "/bacpypes/samples/ReadObjectList.py",
        "virtualenv": "",
        "continuous": false,
        "stdInData": false,
        "x": 730,
        "y": 240,
        "wires": [
            [
                "d33dfc5344b6ee8d"
            ]
        ]
    },
    {
        "id": "d33dfc5344b6ee8d",
        "type": "debug",
        "z": "63fb3651af578236",
        "name": "debug 16",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1180,
        "y": 240,
        "wires": []
    },
    {
        "id": "39be4bef97350806",
        "type": "inject",
        "z": "63fb3651af578236",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "750 10.22.40.61",
        "payloadType": "str",
        "x": 360,
        "y": 240,
        "wires": [
            [
                "21b26a2ea19de941"
            ]
        ]
    }
]

```

Here is a debug if I inject a string containing the two arguments:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/e/eecd5cadf3f080914ea8b423b3b3b7d2c2311c0f.png)

Here is when I change the type to a number and just send the device\_id argument:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/c/8ca7f9c66f8adcc4f9b1ff7ca7aab498901bcd3b.png)

Here is a snip of the script being invoked in the command line:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/e/de5abff78124949ba5ec0c935a59a5794c9dd5ea.png)

Thanks for responding.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [27 January 2023 13:24 UTC](https://discourse.nodered.org/t/multiple-arguments-to-python-shell/74239/4 "2023-01-27T13:24:51Z")

</div>

> [@Rauth](#):
>
> In Node-Red, I can't find a way to satisfy both arguments, as the script is expecting an integer for the ID and a string for the address.

Well, it THINKS it is - but it isn't really. That is a limitation of s command line scripts. But that shouldn't be relevant.

> [@Rauth](#):
>
> If I send both arguments as a single string, the script doesn't accept it and errors out on invalid integer for device\_id.  
> If I inject the ID as a number type, it skips past that error and of course comes back with an error for missing the address.

I've not done this for a while so I might not be exactly right but I think if you make the payload an array, it would probably do the job. Alternatively, you should be able to send both as a single string separated by a space as long as node-red isn't putting quotes around them.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [27 January 2023 14:17 UTC](https://discourse.nodered.org/t/multiple-arguments-to-python-shell/74239/5 "2023-01-27T14:17:47Z")

</div>

What are these dark blue nodes ? Did you try to execute the `/bacpypes/samples/ReadObjectList.py` command with arguments with an exec node instead ?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [28 March 2023 14:17 UTC](https://discourse.nodered.org/t/multiple-arguments-to-python-shell/74239/6 "2023-03-28T14:17:56Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
