gpt4 book ai didi

javascript - 在 Node.js 中获取请求失败(客户端网络套接字在建立安全 TLS 连接之前断开)

转载 作者:行者123 更新时间:2023-12-01 14:59:51 24 4
gpt4 key购买 nike

我刚刚从 Tensorflow Toxicity classifier 加载了样板代码来自 Github page 的示例.

这是 index.js 中的代码-

const toxicity = require('@tensorflow-models/toxicity');

const threshold = 0.9;

toxicity.load(threshold).then((model) => {
const sentences = ['you suck'];

model.classify(sentences).then((predictions) => {
console.log(predictions);
});
});

如果您需要完整的项目,这里是 GitHub repo .

但是当我运行代码时,它给了我以下错误 -
(node:2180) UnhandledPromiseRejectionWarning: FetchError: request to https://storage.googleapis.com/tfjs-models/savedmodel/universal_sentence_encoder/vocab.json failed, reason: Client network socket disconnected before secure TLS connection was established
at ClientRequest.<anonymous> (D:\xampp\htdocs\nodejs-projects\simple-node\node_modules\node-fetch\lib\index.js:1393:11)
at ClientRequest.emit (events.js:310:20)
at TLSSocket.socketErrorListener (_http_client.js:426:9)
at TLSSocket.emit (events.js:310:20)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:2180) 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:2180) [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:2180) [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.js
  • 检查我是否设置了任何代理(我从未这样做过...)

  • 附加信息 -

    操作系统:Windows 10(64 位)(1909 版)
    Node 版本:v12.16.3

    任何帮助将非常感激。

    最佳答案

    上面的代码在我的电脑上运行良好。
    首先运行这个重试

    npm install @tensorflow/tfjs @tensorflow-models/toxicity

    发布您可以运行此代码的帖子
    const toxicity = require('@tensorflow-models/toxicity');

    const threshold = 0.9;

    toxicity.load(threshold).then((model) => {
    const sentences = ['you suck'];

    model.classify(sentences).then((predictions) => {
    console.log(predictions);
    });
    });

    这是我的输出
    enter image description here

    有时模块可能没有完全安装其依赖项。删除您当前的 node_modules 并重试。

    如果以上方法都不起作用。检查您的 Node 版本。使用 TLS 的 Node 10.1.0 中存在错误
    https://github.com/nodejs/node/issues/21088

    更新您的 Node 版本并尝试

    关于javascript - 在 Node.js 中获取请求失败(客户端网络套接字在建立安全 TLS 连接之前断开),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61628209/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com