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

时光总嘲笑我的痴心妄想 提交于 2019-12-16 18:04:42

问题


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?


回答1:


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 ^_^



来源:https://stackoverflow.com/questions/48353091/chrome-native-messaging-throwing-error-when-sending-a-base64-string-to-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!