Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
528 views
in Technique[技术] by (71.8m points)

python - Chrome Native Messaging throwing error when sending a base64 string to client

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
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 ^_^


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...