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

时间:2020-05-06 05:46:02

标签: javascript node.js tensorflow promise

我刚刚从Github pageTensorflow Toxicity classifier示例中加载了样板代码。

这是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.

我在Google中查找了一些错误,类似这样的问题很多,但是没有有效的答案。

为消除可能的问题,我已经做了几件事-

  1. 清洁安装了最新版本的Node.js
  2. 检查是否已设置任何代理(我从未做过...)

其他信息-

OS:Windows 10(64位)(版本1909) 节点版本:v12.16.3

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:7)

上面的代码在我的PC上运行正常。 首先运行此命令重试

class CoroutineDownloadWorker(context: Context, params: WorkerParameters) : CoroutineWorker(context, params) {

    override val coroutineContext = Dispatchers.IO

    override suspend fun doWork(): Result = coroutineScope {
        val jobs = (0 until 100).map {
            async {
                downloadSynchronously("https://www.google.com")
            }
        }

        // awaitAll will throw an exception if a download fails, which CoroutineWorker will treat as a failure
        jobs.awaitAll()
        Result.success()
    }
}

您可以运行此代码的帖子

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

这是我的输出 enter image description here

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

如果上述方法无效。检查您的节点版本。带有TLS的节点10.1.0中存在一个错误 https://github.com/nodejs/node/issues/21088

更新您的节点版本并尝试

答案 1 :(得分:0)

如果这只是一个警告,则可以使用该参数;

--unhandled-rejections=none

以下内容是从node.js文档中复制的;

添加了:v12.0.0,v10.17.0

默认情况下,如果未使用unhandledRejection钩子,则所有未处理的拒绝都会触发警告以及针对第一个未处理拒绝的弃用警告。

使用此标志可以更改发生未处理的拒绝时应发生的情况。可以选择以下三种模式之一:

strict: Raise the unhandled rejection as an uncaught exception.
warn: Always trigger a warning, no matter if the unhandledRejection hook is set or not but do not print the deprecation warning.
none: Silence all warnings.

您可以在这里https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode

了解更多信息