小编tsn*_*ake的帖子

在heroku上的nodejs中生成python脚本

摘要问题:为什么 Heroku 指示os.system('say ...')“未找到”,我该如何解决?

我有一个 Node.js 应用程序,我child_process用来生成一个 Python 脚本,该脚本在给出特定单词时读出音频。我知道当我在 上运行我的服务器时它可以工作localhost:5000,但是当我在 Heroku 上部署它时,我在这篇文章底部的图片中出现错误。我曾尝试添加heroku/pythonbuildpack,但这也不起作用。

我在 Node.js 中的 JS 代码如下所示:

app.get('/perform/:word', readOut)
function readOut(req, res) {

    var spawn = require("child_process").spawn;

    var process = spawn('python', ["./readout.py", req.params.word]);

    res.send("Action completed!")
}
Run Code Online (Sandbox Code Playgroud)

请注意,“操作已完成”确实会发送回我的客户端,因此它正在运行代码。

我通过捕获stderr并将其打印到控制台来意识到存在错误。这仅发生在 Heroku 上,我不确定这意味着什么。我不太确定 python 脚本在正常工作时如何出错localhost,但话说回来,我认为缺乏认识是我的垮台所在。

这是我的 Python 文件的样子:

import os
import sys

os.system('say {}'.format(sys.argv[1]))
Run Code Online (Sandbox Code Playgroud)

错误信息是这样的:

stderr: sh: 1: say: not found
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么 Heroku 会发生这种情况?我是否缺少某个包裹或任何东西?我如何让 Heroku 知道os.system()电话?

编辑:我实际上在 …

python heroku node.js

5
推荐指数
1
解决办法
188
查看次数

如何在 Cookie 上指定 SameSite 和 Secure(使用 axios/React/Node Express)

我有这个聊天应用程序已经运行了一段时间,但突然间它在客户端给了我这个问题:

Because a cookie's SameSite attribute was not set or is invalid, it defaults to SameSite=Lax,
which prevents the cookie from being set in a cross-site context. This behavior protects 
user data from accidentally leaking to third parties and cross-site request forgery.

Resolve this issue by updating the attributes of the cookie:
Specify SameSite=None and Secure if the cookie is intended to be set in cross-site contexts.
Note that only cookies sent over HTTPS may use the Secure attribute.
Run Code Online (Sandbox Code Playgroud)

我在我的 …

cookies node.js express reactjs axios

4
推荐指数
1
解决办法
5354
查看次数

标签 统计

node.js ×2

axios ×1

cookies ×1

express ×1

heroku ×1

python ×1

reactjs ×1