Ошибка получения запроса в Node.js (сетевой сокет клиента отключен до того, как было установлено безопасное соединение TLS) - PullRequest
9 голосов
/ 06 мая 2020

Я только что загрузил шаблонный код из примера 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 .

Но когда я запустите код, он выдает следующую ошибку -

(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. Clean установил последнюю версию Node.js
  2. Проверено, настроен ли у меня какой-либо прокси (у меня никогда так не делал ...)

Дополнительная информация -

ОС: Windows 10 (64 бит) (Версия 1909) Версия узла: v12.16.3

Любая помощь будет принята с благодарностью.

Ответы [ 2 ]

6 голосов
/ 09 мая 2020

Приведенный выше код отлично работает на моем P C. Повторите попытку, запустив этот первый

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 и повторите попытку.

Если вышеуказанные методы не сработали. Проверьте версию своего узла. Ошибка в узле 10.1.0 с TLS https://github.com/nodejs/node/issues/21088

Обновите версию своего узла и попробуйте

0 голосов
/ 15 мая 2020

Если это просто предупреждение, вы можете использовать аргумент;

--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

...