var base64 = require("base-64");
var utf8 = require("utf8");
const data = [{"browser_open":""http://www.bilibili.com""},{"closeBrowser": ""}]
// 测试automagica
app.post("/3", (req, res, next) => {
console.log(req.body, "req.body");
var bytes = utf8.encode(JSON.stringify(data));
var encoded = base64.encode(bytes);
let options = {
pythonPath: "python",
// pythonOptions: ['-d'], // get print results in real-time
args: ["-d",encoded],
};
console.log(options.args, "data");
PythonShell.run("backend/b64argparse.py", options, function (err, result) {
if (err) throw err;
console.log("result: ", result.toString());
res.send(result.toString());
});
});
等价于的代码是
python b64argparse.py
-d "W3siYnJvd3Nlcl9vcGVuIjoiXCJodHRwOi8vd3d3LmJpbGliaWxpLmNvbVwiIn1d"