error: Error parsing JSON:[{"keys": ..........while running publishmulti command

+1 vote
code:

import argparse
import subprocess
import time
import json
import os
import signal
import getpass
import psutil
import math
import pandas as pd

def test():
    publishitems=[]
     
    data1= {"a1":["2334","?452" ],
           "T1": ["tag1","tg"],
           "Q1": ["c1","c2"]
          }
    df1=pd.DataFrame(data1)
    #print(df1)
    data=df1.to_dict()
    #data=json.dumps(data)
    keyString='key'
 
    #item={"keys":[keyString],"data":data}
    item={"keys":[keyString],"data":{"json": data} }
    publishitems.append(item)
    data2= {"a1":["24","?42" ],
           "T1": ["tag1","tg" ],
           "Q1": ["cc1","mm"]
          }
    df2=pd.DataFrame(data2)
    data=df2.to_dict()
    #data=json.dumps(data)
    item={"keys":[keyString],"data":{"json":  data}}
    publishitems.append(item)
    print(publishitems)
    import json
    class mylist(list):
        def __str__(self):
            return json.dumps(self)
    pairs =  mylist(publishitems)
    #publishcmd= 'multichain-cli chaintxx publishmulti test \'{}\' '.format( (publishitems))
    publishcmd= 'multichain-cli chaintxx publishmulti test {} '.format( (pairs))
    print(publishcmd)
    daemonOut = subprocess.call(publishcmd.split())
    return 'finish'

def main():
    #createStreamCommand= 'multichain-cli chaintxx create stream test true'
    
    #procCreate = subprocess.Popen(createStreamCommand.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    #procCreate.wait()
            
    subscribeStreamCommand= 'multichain-cli {} subscribe {}'.format('chaintxx', 'test')
    #subscribe to the stream
    procSubscribe = subprocess.Popen(subscribeStreamCommand.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    procSubscribe.wait()
    print(test())
    

if __name__ == "__main__":
    main()

 

output:

$ python3 testdf.py
[{'keys': ['key'], 'data': {'json': {'a1': {0: '2334', 1: '?452'}, 'T1': {0: 'tag1', 1: 'tg'}, 'Q1': {0: 'c1', 1: 'c2'}}}}, {'keys': ['key'], 'data': {'json': {'a1': {0: '24', 1: '?42'}, 'T1': {0: 'tag1', 1: 'tg'}, 'Q1': {0: 'cc1', 1: 'mm'}}}}]
multichain-cli chaintxx publishmulti test '[{"keys": ["key"], "data": {"json": {"a1": {"0": "2334", "1": "?452"}, "T1": {"0": "tag1", "1": "tg"}, "Q1": {"0": "c1", "1": "c2"}}}}, {"keys": ["key"], "data": {"json": {"a1": {"0": "24", "1": "?42"}, "T1": {"0": "tag1", "1": "tg"}, "Q1": {"0": "cc1", "1": "mm"}}}}]'
error: Error parsing JSON:'[{"keys":

but when directly running publishmulti command on terminal directly, there is no error.

 $ multichain-cli chaintxx publishmulti test '[{"keys": ["key"], "data": {"json": {"a1": {"0": "2334", "1": "?452"}, "T1": {"0": "tag1", "1": "tg"}, "Q1": {"0": "c1", "1": "c2"}}}}, {"keys": ["key"], "data": {"json": {"a1": {"0": "24", "1": "?42"}, "T1": {"0": "tag1", "1": "tg"}, "Q1": {"0": "cc1", "1": "mm"}}}}]'
{"method":"publishmulti","params":["test",[{"keys":["key"],"data":{"json":{"a1":{"0":"2334","1":"?452"},"T1":{"0":"tag1","1":"tg"},"Q1":{"0":"c1","1":"c2"}}}},{"keys":["key"],"data":{"json":{"a1":{"0":"24","1":"?42"},"T1":{"0":"tag1","1":"tg"},"Q1":{"0":"cc1","1":"mm"}}}}]],"id":"20274801-1718340965","chain_name":"chaintxx"}

9aab28705586beef188662d401a6cbcdbd20bb0170ec0d90c0d567a28bf1d867

can anyone help me out in finding the issue?
asked Jun 14 by anju

1 Answer

0 votes

I'm afraid we can't get too deep into debugging your Python code, but it appears that the problem might be in the split() method you're using, which is turning the string into an array.

answered Jun 14 by MultiChain
...