Chrome Native message generation error when sending base64 string to client

Using Chrome Nationwide Messages an example application as a template can make a bash system call

 os.system("<bash command>") 

Requirement - return base64 string from python script

 os.system("<bash command that returns a base64 string>") 

which can check the expected return result in terminal .

However, when setting up the code in native-messaging-example-host on lines 97-98 on

 dataurl = os.system("<bash command that returns a base64 string>") text = '{"text": "' + dataurl + '"}' 

the application window closes and

 Failed to connect: Error when communicating with the native messaging host. 

printed on the HTML application page.

When using the source code

 text = '{"text": "' + self.messageContent.get() + '"}' 

and sending the base64 string corresponding to the output that the bash command outputs to the python host, base64 sent back to the client. The length of the base64 string being tested is 43304 , which is less than the maximum size of 1 MB messages sent from the host. The maximum number of messages sent from the host.

Why does the application throw an error and not send the base64 string from the python host to the Chromium client?

0
source share
1 answer
 import supprocess as sub ter = sub.Popen("<bash command that returns a base64 string>", shell=True,stdout=sub.PIPE) tread = cmd.communicate()[0].decode("u8") text = '{"text": "' + tread + '"}' 

Try it ^ _ ^

0
source

Source: https://habr.com/ru/post/1275068/


All Articles