Ask / Submit

Error passing argument to pyotherside [answered]

asked 2018-10-31 19:38:47 +0200

DaveRo gravatar image

I'm stuck on an error in an app I'm writing. It will (eventually) SSH to a server and issue commands which I will generate by tapping buttons on my Jolla C. (The server is a headless bananaPi running the xmms2 music player.)

To issue commands to a command shell I have a python module (based on the SDK python example). I want to send it a command to pass to the shell and have it send stdout back to the qml to display.

I've already tested that tapping the button runs the python function, that it can issue a command to the shell, and that it will send stdout back to the qml and display it. I now want to generalise it by passing the command (ssh, xmms2 play, etc) to the python function as a argument. But I cannot get the argument-passing to work. I expect there's some basic error but I cannot see it.

Here is the relevant qml. The button called Connect will issue an ssh command, though for testing it issues just 'ls'.

            Row {
            Button {
                text: "Connect"
                onClicked: python.connect("ls")

Python {
    id: python

    Component.onCompleted: {
        importModule('commander', function(){});


    function connect(cmd) {
        var cmdarg = 'args=["'+cmd+'"]';
        call('commander.command.issuecommand', cmdarg, function(){});

Here is the python module:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import pyotherside
import tempfile
import subprocess

class Command:
  def __init__(self):

  def issuecommand(self, cmd):

    with tempfile.TemporaryFile() as outfile:, stdout=outfile)

command = Command()

And here's the error. The first line is the console.log showing the value of the 2nd argument to the call.

[D] connect:66 - args=["ls"]
[D] unknown:0 - "PyOtherSide error: issuecommand() missing 1 required positional argument: 'cmd'"
[D] onError:72 - python error: Return value of PyObject call is NULL: issuecommand() missing 1 required positional argument: 'cmd'

edit retag flag offensive reopen delete

The question has been closed for the following reason "the question is answered, an answer was accepted" by DaveRo
close date 2018-10-31 22:06:22.845130


@cy8aer Many thanks. This works:
call('commander.command.issuecommand', [cmd], function(){});

I had interpreted the spec to mean that args= was a keyword argument:

A supplementary question:
I'm displaying the stdout text in a TextArea field, but it shouldn't be editable. I really want a multi-line display field but I don't see one here:
What to use?

DaveRo ( 2018-10-31 20:28:14 +0200 )edit

Use Label? Probably you can find more help with my podqast application:

cy8aer ( 2018-10-31 20:34:15 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2018-10-31 19:48:52 +0200

cy8aer gravatar image

updated 2018-10-31 19:49:45 +0200

Use square brackets for arguments (this is an array)!

call('commander.command.issuecommand', [arg1, arg2, arg3, ...], function(){});
edit flag offensive delete publish link more

Question tools

1 follower


Asked: 2018-10-31 19:38:47 +0200

Seen: 101 times

Last updated: Oct 31 '18