首页 > 解决方案 > 如何将大量数据从 node.js 应用程序发送到 python 文件?

问题描述

我有一个包含 2 个(或更多)嵌套对象的 json 对象,每个对象中有 18 个键值对,基本上 json 对象是一个存储文章的对象,每个嵌套对象都包含此类信息。

{
createdAt: date,
lastUpdated: date,
content: of 250 words,
...
.
.
.
.
.
.

and many more fields
}

现在我想将此对象发送到某个机器学习应用程序的 python 文件,并且我已经使用 spawn 模块完成了它,我通过以下命令发送此数据:

const childPython = spawn('python', ['hello.py',JSON.stringify(posts)])

但它显示了这个错误:

(node:21728) UnhandledPromiseRejectionWarning: Error: spawn ENAMETOOLONG
    at ChildProcess.spawn (internal/child_process.js:403:11)
    at spawn (child_process.js:553:9)
    at Object.showObj.getSimilarArticles (D:\done\VSCode\learners backend v2\controllers\showPageController.js:92:27)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async D:\done\VSCode\learners backend v2\routes\posts.js:1519:3
(Use `node --trace-warnings ...` to show where the warning was created)
(node:21728) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:21728) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

现在我的问题是,是不是因为尺寸大,如果是,还有其他解决方案可以传达数据吗?如果没有,我做错了什么,我该如何纠正?

标签: node.jsjsonobjectspawn

解决方案


推荐阅读