Im getting the following error when attempting to connect to gmail through node:
node:events:368
throw er;
// Unhandled 'error' event
^
Error: 9C470000:error:0A00010B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:355:
at Socket.ondata (node:internal/js_stream_socket:77:22)
at Socket.emit (node:events:390:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Socket.Readable.push (node:internal/streams/readable:234:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
Emitted 'error' event on Connection instance at:
at TLSSocket._onError (C:\Users\my-app1\node_modules\imap\lib\Connection.js:151:10)
at TLSSocket.emit (node:events:390:28)
at emitErrorCloseNT (node:internal/streams/destroy:129:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
library: 'SSL routines',
reason: 'wrong version number',
code: 'ERR_SSL_WRONG_VERSION_NUMBER',
source: 'socket'
}
Node.js v17.3.1
PS C:\Users\my-app1\server-app> node imap
node:events:368
throw er; // Unhandled 'error' event
^
Error: 98400000:error:0A00010B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:355:
at Socket.ondata (node:internal/js_stream_socket:77:22)
at Socket.emit (node:events:390:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Socket.Readable.push (node:internal/streams/readable:234:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
Emitted 'error' event on Connection instance at:
at TLSSocket._onError (C:\Users\my-app1\node_modules\imap\lib\Connection.js:151:10)
at TLSSocket.emit (node:events:390:28)
at emitErrorNT (node:internal/streams/destroy:164:8)
at emitErrorCloseNT (node:internal/streams/destroy:129:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
library: 'SSL routines',
reason: 'wrong version number',
code: 'ERR_SSL_WRONG_VERSION_NUMBER',
source: 'socket'
}
Node.js v17.3.1
This is the code:
const Imap = require('imap');
const simpleParser = require('mailparser').simpleParser;
const fs = require('fs');
const imap = new Imap({
user: 'your-email-address',
password: 'your-email-password',
host: 'imap.example.com',
port: 993,
tls: true,
tlsOptions: {
rejectUnauthorized: false,
ca: [ fs.readFileSync('path/to/ca.crt') ]
}
});
imap.once('ready', function() {
imap.openBox('INBOX', true, function(err, box) {
if (err) throw err;
imap.search([ 'UNSEEN', ['SINCE', 'January 15, 2021'] ],
function(err, results) {
if (err) throw err;
if (results.length > 0) {
var f = imap.fetch(results, { bodies: '' });
f.on('message', function(msg, seqno) {
msg.on('body', function(stream, info) {
simpleParser(stream, (err, mail) => {
console.log(mail.subject);
console.log(mail.text);
});
});
});
f.once('error', function(err) {
console.log('Fetch error: ' + err);
});
f.once('end', function() {
console.log('Done fetching all unseen messages.');
imap.end();
});
} else {
console.log('No new messages.');
imap.end();
}
});
});
});
imap.once('error', function(err) {
console.log(err);
});
imap.once('end', function() {
console.log('Connection ended.');
});
imap.connect();
Any help would be greatly appreciated.
Related
So I am trying to get some data from the food-data-central API. In my program I console log the data, but I don't get any results on the console.
The only thing I get is an error about Fetch Error
import fetch from "node-fetch"
const params = {
api_key: <apiKey>,
query: 'chicken breast raw',
dataType: ["Survey (FNDDS)"],
pagesize: 5,
}
const api_url = `https://api.nal.usda.gov/fdc/v1/foods/search?api_key=${encodeURIComponent(params.api_key)}&query=${encodeURIComponent(params.query)}&dataType=${encodeURIComponent(params.dataType)}&pageSize=${encodeURIComponent(params.pagesize)}`
function getData(){
return fetch(api_url).then(response => response.json())
}
getData().then(data => {
const foods = data.foods[0];
console.log("Protein: ");
console.log(foods.foodNutrients[0].value);
console.log("Fats: ");
console.log(foods.foodNutrients[1].value);
console.log("Carbs: ");
console.log(foods.foodNutrients[2].value);
});
The output that I get:
reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err));
^
FetchError: request to https://api.nal.usda.gov/fdc/v1/foods/search?api_key=3Bi6rNu3MiTYMaPwMf2u5vs1xAtdKS0n5HoFpgy9&query=chicken%20breast%20raw&dataType=Survey%20(FNDDS)&pageSize=5 failed, reason: connect ETIMEDOUT 2600:1f12:18a:7d00:217:68d:2c2:3718:443
at ClientRequest.<anonymous> (/home/dflorian251/Desktop/node_modules/node-fetch/lib/index.js:1505:11)
at ClientRequest.emit (node:events:513:28)
at TLSSocket.socketErrorListener (node:_http_client:481:9)
at TLSSocket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
type: 'system',
errno: 'ETIMEDOUT',
code: 'ETIMEDOUT'
Is something wrong with the node-fetch module ?
i wrote this code from sequelize documentation.
i created a databade in pgadmin with the name of users and pasword 12345 and o thought it should be connected to the db. but it does not. at first it write the " Connection has been established successfully. "
in the terminal but then i catch an error.
const { Sequelize } = require('sequelize');
const sequelize = new Sequelize('postgres://Admin:12345:5432/users')
try {
sequelize.authenticate();
console.log('Connection has been established successfully.');
} catch (error) {
console.error('Unable to connect to the database:', error);
}
the error:
reject(new sequelizeErrors.HostNotFoundError(err));
^
HostNotFoundError [SequelizeHostNotFoundError]: getaddrinfo ENOTFOUND admin
at Client._connectionCallback (C:\Users\moham\OneDrive\Desktop\jalese1\node_modules\sequelize\lib\dialects\postgres\connection-manager.js:133:24)
at Client._handleErrorWhileConnecting (C:\Users\moham\OneDrive\Desktop\jalese1\node_modules\pg\lib\client.js:305:19)
at Client._handleErrorEvent (C:\Users\moham\OneDrive\Desktop\jalese1\node_modules\pg\lib\client.js:315:19)
at Connection.emit (node:events:527:28)
at Socket.reportStreamError (C:\Users\moham\OneDrive\Desktop\jalese1\node_modules\pg\lib\connection.js:52:12)
at Socket.emit (node:events:527:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
parent: Error: getaddrinfo ENOTFOUND admin
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'admin'
},
original: Error: getaddrinfo ENOTFOUND admin
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'admin'
}
}
where is the problem?
This code is producing an error in spite of a try-catch block... It should send a error message, if the server isn't reachable and a positive message, if ist is.
try {
net.connect(25565, "mc.hypixel.net", () => {
console.log("connected");
});
} catch (err) {
console.log("not connected");
}
This is the error:
events.js:292
throw er; // Unhandled 'error' event
^
Error: connect ETIMEDOUT 104.16.78.21:25565
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
Emitted 'error' event on Socket instance at:
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
errno: -4039,
code: 'ETIMEDOUT',
syscall: 'connect',
address: '104.16.78.21',
port: 25565
}
Thank you for your help :)
hmm.. I believe the following answer is what net suggests
try this
net.connect(25565, "mc.hypixel.net", () => {
console.log("connected");
})
.on('error', (err)=>console.log("not connected"));
I'm making a discord bot with Node.js and erela.js, but when I try to get the server that handles erela on, it shows me this error:
A node error occured: connect ECONNREFUSED ::1:50106
2020-05-01T21:23:19.367157+00:00 app[worker.1]: events.js:287
2020-05-01T21:23:19.367175+00:00 app[worker.1]: throw er; // Unhandled 'error' event
2020-05-01T21:23:19.367176+00:00 app[worker.1]: ^
2020-05-01T21:23:19.367176+00:00 app[worker.1]:
2020-05-01T21:23:19.367177+00:00 app[worker.1]: Error: connect ECONNREFUSED ::1:50106
2020-05-01T21:23:19.367178+00:00 app[worker.1]: at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
2020-05-01T21:23:19.367179+00:00 app[worker.1]: Emitted 'error' event on WebSocket instance at:
2020-05-01T21:23:19.367179+00:00 app[worker.1]: at ClientRequest.<anonymous> (/app/node_modules/ws/lib/websocket.js:554:15)
2020-05-01T21:23:19.367179+00:00 app[worker.1]: at ClientRequest.emit (events.js:310:20)
2020-05-01T21:23:19.367180+00:00 app[worker.1]: at Socket.socketErrorListener (_http_client.js:426:9)
2020-05-01T21:23:19.367181+00:00 app[worker.1]: at Socket.emit (events.js:310:20)
2020-05-01T21:23:19.367181+00:00 app[worker.1]: at emitErrorNT (internal/streams/destroy.js:92:8)
2020-05-01T21:23:19.367181+00:00 app[worker.1]: at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
2020-05-01T21:23:19.367182+00:00 app[worker.1]: at processTicksAndRejections (internal/process/task_queues.js:84:21) {
2020-05-01T21:23:19.367185+00:00 app[worker.1]: errno: 'ECONNREFUSED',
2020-05-01T21:23:19.367185+00:00 app[worker.1]: code: 'ECONNREFUSED',
2020-05-01T21:23:19.367185+00:00 app[worker.1]: syscall: 'connect',
2020-05-01T21:23:19.367186+00:00 app[worker.1]: address: '::1',
2020-05-01T21:23:19.367186+00:00 app[worker.1]: port: 50106
The index.js code is:
const discord = require("discord.js");
const fs = require("fs");
const bot = new discord.Client({disableEveryone: true});
const prefix = "."
const token = process.env.token;
const { ErelaClient } = require('erela.js');
function server () {
require ("./server.js");
}
// When bot ready
bot.on("ready", async () => {
server();
bot.music = new ErelaClient(bot, [
{
host: process.env.HOST,
port: process.env.PORT,
password: process.env.PASSWORD
}
]);
bot.music.on("nodeConnect", node => console.log("New node connected, music is now working on the bot!"));
bot.music.on("nodeError", (node, error) => console.log(`A node error occured: ${error.message}`));
And the server.js code is:
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
});
app.listen(7000, function () {
console.log('Example app listening on port 7000, so erela will work!');
});
I don't know why it's happening. If someone has an answer for this. I'd be grateful
If you have two servers running on the same PC, you should enable CORS to allow communications between both of them.
Add in the server.js file:
const cors = require('cors')
app.use(cors())
Also, install in CLI:
npm install cors
CORS npm link
Hope this can help you.
I am trying to get 200 status code in response, but as a result it's ETIMEDOUT.
I can't understand, how is it possible that I can grab successful response via postman, but same via node-fetch responding with ETIMEDOUT always.
Here is an example of code:
const Resource = {
get: cb => {
fetch('https://example.com', {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: {...some body...},
}).then(res => {
if (res.status !== 200) cb(`Status: ${res.status}, ${res.statusText}`)
return res.text()
}).then(data => {
cb(null, data)
}).catch((err) => {
console.log('ERROR: ', err)
})
}
}
and here is response:
ERROR: { FetchError: request to https://example.com failed, reason: connect ETIMEDOUT
at ClientRequest.<anonymous> (C:\Users\projects\DSSRQ\node_modules\node-fetch\lib\index.js:1393:11)
at emitOne (events.js:116:13)
at ClientRequest.emit (events.js:211:7)
at TLSSocket.socketErrorListener (_http_client.js:387:9)
at emitOne (events.js:116:13)
at TLSSocket.emit (events.js:211:7)
at emitErrorNT (internal/streams/destroy.js:64:8)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
message: 'request to https://example.com failed, reason: connect ETIMEDOUT',
type: 'system',
errno: 'ETIMEDOUT',
code: 'ETIMEDOUT' }
It looks like it was because of the proxy limitation.