Jump to content
Sign in to follow this  
Julio Cesar Mendez

RPC Request javascript to python

Recommended Posts


I'm using RPC.Query to send a string from js to py.

At py receptor this scrash using json.loads(..) de args.

The messages error is:
... JSONDecoderError(\"Expecting value\", s, err.value) from None\njson.decoder.JSONDecodeEror: Expecting value: line 1 colum1 (char 0)\n", "message": "Expecting value: line 1, column 1 (char 0)"], "Exception_type":"internal_error"}}"


I do an console.log(..) beford RPC instruction and the string value is ok.

That is the code:


            // *JCM*
            var strcontenido = '';
            var LF = '\n';
            var orderi = JSON.parse(JSON.stringify(order));
            var orderf = JSON.parse(JSON.stringify(order_flushed));
            strcontenido ="80#DOCUMENTO DE PRUEBA +LF80_is*YO MISMO+LF80_ir*22157456+LF80_i03Dirección: Calle, 12345678 Ciudad, Venezuela+LF80_i04Teléfono:  +584161236548+LF80_i05Referencia: 00001-317-0204+LF80_i06Mesa: M5, Comensales: 1+LF80_@*****Gracias por su compra*****+LF80_#000000010000001000Golosinas+LF101"
            strcontenido= strcontenido.split(":").join("?");  // Replace ":" with "?" to send to py
            strcontenido= strcontenido.split(",").join("-");   // Replace "," with "-" to send to py
            console.log(strcontenido);        // This show ok
            errTxt = self._crear_factura( true, strcontenido);

            var transfer = self._flush_orders([order_flushed], {timeout:30000, to_invoice:true});
            // *JCM*

        // ...do some...
            return done;
        return invoiced;

    // Envia comandos al programa en python- Send command to py

    _crear_factura: function(imprime, strcontenido) {
        var self = this;
        var ejecuted = true;

    strcontenido = '{"F": "\'' +strcontenido + '\'"}'    // Converting string to json inserting  {"id": '...string...'} format
    var args = JSON.parse(strcontenido);
    console.log('ARGS=>>'+args);            // This show text ok >> 80#DOCUMENTO DE PRUEBA +LF80_is*YO MISMO+LF80_ir*22157456+LF80_i03Dirección? Calle- 12345678 Ciudad- Venezuela+LF80_i04Teléfono?  +584161236548+LF80_i05Referencia? 00001-317-0204+LF80_i06Mesa? M5- Comensales? 1+LF80_@*****Gracias por su compra*****+LF80_#000000010000001000Propinas+LF101

        if (imprime) {
            return rpc.query({
                    model: 'pos.order',
                    method: 'print_ticket',
                    args: args,
        }).fail(function(error, event){
                ejecuted = false;
            console.log('_crear_factura (\n' + strcontenido +'\n): Ejecutada...!!!');
        } else {
            console.log('_crear_factura (\n' + strcontenido +'\n): NO EJECUTADA...!!!');
        return ejecuted;


FROM py:

    def print_ticket(self, strcontenido):
        #contenido = strcontenido.get('F')            // Error: strcontenido d'nt have get method
        contenido = json.loads(strcontenido)            // Error: previus commented


        #if strcontenido.get('F'):            // Error: strcont....
        #    contenido = strcontenido['strcontenido']

        errVal=f.write(contenido["F"])                // Never cross at this...

        #    errVal=f.write('***** GENERAR LA FACTURA*****\n\n')

        #for data in strcontenido: errVal=f.write(data)
        errVal=f.write('\n\n*****FIN DEL ARCHIVO******\\nn')

        errVal = f.close()

        return True

So,  I had proved some method without result....

¿Do you have any idea to resolv...??

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...