Chrome Native Messaging throwing error when sending a base64 string to client
Asked Answered
M

1

-1

Using Chrome Native Messaging sample app as a template am able make a system call to bash

os.system("<bash command>")

The requirement is to return a base64 string from the python script

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

which can verify returns expected result at terminal.

However, when adjust the code at native-messaging-example-host at lines 97-98 to

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.

is printed at the applications' HTML page.

When using the original code

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

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

Why is the application throwing an error and not sending the base64 string from the python host to the Chromium client?

Mcmahon answered 20/1, 2018 at 5:56 Comment(0)
R
0
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 This ^_^

Rie answered 20/1, 2018 at 6:21 Comment(1)
Tried the code substituting subprocess for supprocess though the string is not sent to client. The string sent to host is echoed.Mcmahon

© 2022 - 2024 — McMap. All rights reserved.