admin管理员组文章数量:1244296
I just loaded the boilerplate code from the Tensorflow Toxicity classifier
example from this Github page.
Here's the code in 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);
});
});
If you need the full project, here's the GitHub repo.
But when I run the code, it gives me the following error -
(node:2180) UnhandledPromiseRejectionWarning: FetchError: request to .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 .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.
I have looked up some the error in Google, there's a lot of questions like these but no valid answers.
Here's a few things I've done already to eliminates as a possible problem -
- Clean installed the latest version of Node.js
- Checked if I have any proxy set up (I've never done so...)
Additional info -
OS: Windows 10 (64 Bit) (Version 1909) Node Version: v12.16.3
Any help would be much appreciated.
I just loaded the boilerplate code from the Tensorflow Toxicity classifier
example from this Github page.
Here's the code in 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);
});
});
If you need the full project, here's the GitHub repo.
But when I run the code, it gives me the following error -
(node:2180) UnhandledPromiseRejectionWarning: FetchError: request to https://storage.googleapis./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/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.
I have looked up some the error in Google, there's a lot of questions like these but no valid answers.
Here's a few things I've done already to eliminates as a possible problem -
- Clean installed the latest version of Node.js
- Checked if I have any proxy set up (I've never done so...)
Additional info -
OS: Windows 10 (64 Bit) (Version 1909) Node Version: v12.16.3
Any help would be much appreciated.
Share Improve this question asked May 6, 2020 at 5:46 Evading ShadowsEvading Shadows 4891 gold badge6 silver badges24 bronze badges3 Answers
Reset to default 8 +25The above code works fine on my PC. Retry by running this first
npm install @tensorflow/tfjs @tensorflow-models/toxicity
Post which you can run this code
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);
});
});
Here is my output
Sometimes the module might not have installed its dependencies pletely. Delete your current node_modules and retry.
If the above methods didn't work. Check your node version. There is a bug in node 10.1.0 with TLS https://github./nodejs/node/issues/21088
Update your node version and try
If this is just a warniing, you may use the argument;
--unhandled-rejections=none
Below is copied from node.js documentation;
Added in: v12.0.0, v10.17.0
By default all unhandled rejections trigger a warning plus a deprecation warning for the very first unhandled rejection in case no unhandledRejection hook is used.
Using this flag allows to change what should happen when an unhandled rejection occurs. One of three modes can be chosen:
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.
You may read more here https://nodejs/api/cli.html#cli_unhandled_rejections_mode
I faced the same error while using node-fetch and deploying my app within Docker container.
Found out that issue was in using node:20-alpine3.17 image.
After downgrading to node:18-alpine3.19 issue resolved.
本文标签:
版权声明:本文标题:javascript - Fetch request failing in Node.js (Client network socket disconnected before secure TLS connection was established) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740189280a2238794.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论