web-dev-qa-db-ja.com

Node.jsでフェッチ要求が失敗する(セキュアなTLS接続が確立される前にクライアントネットワークソケットが切断される)

これからTensorflow Toxicity classifierの例のボイラープレートコードをロードしたところです Githubページ

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.

私はグーグルでいくつかのエラーを調べました、これらのような多くの質問がありますが、有効な答えはありません。

考えられる問題として排除するために私がすでに行ったいくつかのことを以下に示します-

  1. Node.jsの最新バージョンをクリーンインストールしました
  2. プロキシが設定されているかどうかを確認しました(設定したことがない...)

追加情報 -

OS:Windows 10(64ビット)(バージョン1909)Nodeバージョン:v12.16.3

どんな助けでも大歓迎です。

9
Evading Shadows

これが単なる警告である場合は、引数を使用できます。

--unhandled-rejections=none

以下はnode.jsのドキュメントからコピーされています。

追加:v12.0.0、v10.17.0

デフォルトでは、すべての未処理の拒否は警告に加えて、unhandledRejectionフックが使用されていない場合の最初の未処理の拒否に対する非推奨警告をトリガーします。

このフラグを使用すると、未処理の拒否が発生した場合の動作を変更できます。 3つのモードのいずれかを選択できます。

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

0
alfred