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

2024/11/19 14:47:12

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?

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

https://en.xdnf.cn/q/118517.html

Related Q&A

Exporting DataFrame to Excel using pandas without subscribe

How can I export DataFrame to excel without subscribe? For exemple: Im doing webscraping and there is a table with pagination, so I take the page 1 save it in DataFrame, export to excel e do it again …

Fraction of a real number in python giving complicated answer

Importing Fraction from fractions to give a fractional representation of a real number, but giving responses quite complicated which seems very simple by the paper-pen method. Fractions(.2) giving answ…

Scrape latitude and longitude (Google Maps) inside Script type=text/javascript

Im beginner in Web Scrapping. Im trying to get latitude and longitude from this web: https://urbania.pe/inmueble/proyecto/ememhvin-proyecto-mariscal-castilla-lima-santiago-de-surco-tale-inmobiliaria-65…

How to delete a button that is made by a loop

from tkinter import *class Main:def __init__(self, root):for i in range(0, 9):for k in range(0, 9):Button(root, text=" ").grid(row=i, column=k)root.mainloop()root = Tk()x = Main(root)How do I…

Invalid array shape with neural network using Keras?

Currently studying the Deep Learning with Python book by Francios Chollet. I am very new to this and I am getting this error code despite following his code verbatim. Can anyone interpret the error mes…

How to download PDF files from a list of URLs in Python?

I have a big list of links to PDF files that I need to download (500+) and I was trying to make a program to download them all because I dont want to manually do them. This is what I have and when I tr…

Training on GPU much slower than on CPU - why and how to speed it up?

I am training a Convolutional Neural Network using Google Colabs CPU and GPU. This is the architecture of the network: Model: "sequential" ____________________________________________________…

Check list item is present in Dictionary

Im trying to extend Python - Iterate thru month dates and print a custom output and add an addtional functionality to check if a date in the given date range is national holiday, print "NH" a…

a list of identical elements in the merge list

I need to merge the list and have a function that can be implemented, but when the number of merges is very slow and unbearable, I wonder if there is a more efficient way Consolidation conditions:Sub-…

How To Get A Contour Of More/Less Of The Expected Area In OpenCV Python

I doing some contour detection on a image and i want to find a contour based on a area that i will fix in this case i want the contour marked in red. So i want a bounding box around the red contour Fol…