In my sample project, I have used Google recaptcha. I need to verify captcha response at back end (Node JS). In NodeJS, I have used request module to connect with google server. But, I got some error like following
Error: connect ECONNREFUSED 172.217.166.100:443
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
Node JS
formData = {
secret: 'xxxxxx',
response: 'yyyyyy'
}
request.post({
url: "https://www.google.com/recaptcha/api/siteverify",
form: formData
},
function (err, httpResponse, body) {
if (err) throw err;
if (body) {
res.send(body);
}
});
When I am trying to set proxy to this above NodeJS code like following...
formData = {
secret: 'xxxxxx',
response: 'yyyyyy'
}
request.post({
url: "https://www.google.com/recaptcha/api/siteverify",
form: formData,
proxy: '172.217.166.100' /// Google server IP
},
function (err, httpResponse, body) {
if (err) throw err;
if (body) {
res.send(body);
}
});
I got these errors....
Error: tunneling socket could not be established, cause=connect ECONNREFUSED 127.0.0.1:80
at ClientRequest.onError (C:\Users\Desktop\project\Backend\node_modules\tunnel-agent\index.js:177:17)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:116:13)
at ClientRequest.emit (events.js:211:7)
at Socket.socketErrorListener (_http_client.js:387:9)
at emitOne (events.js:116:13)
at Socket.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)
Can anyone help me to resolve this problem
Thanks in advance
Looks like you've specified something like,
proxy: '172.217.166.100' /// Google server IP
which is wrong, as you can't determine the IP address of google since it is dynamic and often changes it.
You can obtain a latest proxy IP from the below link,
https://code.google.com/archive/p/recaptcha/wikis/FirewallsAndRecaptcha.wiki
The latest available IP's are,
ip4:216.239.32.0/19 ip4:64.233.160.0/19 ip4:66.249.80.0/20
ip4:72.14.192.0/18 ip4:209.85.128.0/17 ip4:66.102.0.0/20
ip4:74.125.0.0/16 ip4:64.18.0.0/20 ip4:207.126.144.0/20
ip4:173.194.0.0/16
Hope this helps!
Related
I am learning NodeJS in w3schools.com at this link, in MongoDB section i get error and i can't solve it.
Create a database called "mydb":
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/mydb";
MongoClient.connect(url, function(err, db) {
if (err) throw err;
console.log("Database created!");
db.close();
});
Save the code above in a file called "demo_create_mongo_db.js" and run the file
C:\Users\myName>node demo_create_mongo_db.js
then i get this error
(node:6104) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
C:\Users\Milad\node_modules\mongodb\lib\utils.js:725
throw error;
^
MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16) {
name: 'MongoNetworkError',
[Symbol(mongoErrorContextSymbol)]: {}
}]
at Pool.<anonymous> (C:\Users\Milad\node_modules\mongodb\lib\core\topologies\server.js:438:11)
at Pool.emit (events.js:311:20)
at C:\Users\Milad\node_modules\mongodb\lib\core\connection\pool.js:561:14
at C:\Users\Milad\node_modules\mongodb\lib\core\connection\pool.js:994:11
at C:\Users\Milad\node_modules\mongodb\lib\core\connection\connect.js:31:7
at callback (C:\Users\Milad\node_modules\mongodb\lib\core\connection\connect.js:264:5)
at Socket.<anonymous> (C:\Users\Milad\node_modules\mongodb\lib\core\connection\connect.js:294:7)
at Object.onceWrapper (events.js:418:26)
at Socket.emit (events.js:311:20)
at emitErrorNT (internal/streams/destroy.js:92:8) {
name: 'MongoNetworkError',
[Symbol(mongoErrorContextSymbol)]: {}
}
I tried the next chapter lesson but get the same error.
I am using windows10x64
First install MongoDB!
I thought Node.js had installed MongoDB on my machine.
before running node app you should first install mango on your machine
check on the below link how to download and install it:
https://www.mongodb.com/try/download/community
Sails server:
Windows 10 64-bit
Sails.js 1.0.0-36
Node.js 6.10.2
MongoDB server:
Centos 7 on Virtualbox, host networking only
Mongodb 3.4.4, listening to all interfaces, no auth configured
I can successfully lift Sails, connect the datastore, and use the models without any problem.
However, this test will result on a timeout:
let mongo = require('mongodb');
let uri = 'mongodb://' + process.env.MONGO_SERVER + ':' + process.env.MONGO_PORT + '/sails';
mongo.MongoClient.connect(uri, function(err, db) {
if(err){
return res.serverError(err);
}
return res.json("open");
});
{ MongoError: failed to connect to server [192.168.99.2:27027] on first connect [MongoError: connect ETIMEDOUT 192.168.99.2:27027]
at Pool.<anonymous> (....\node_modules\mongodb-core\lib\topologies\server.js:329:35)
at emitOne (events.js:96:13)
at Pool.emit (events.js:188:7)
at Connection.<anonymous> (....\node_modules\mongodb-core\lib\connection\pool.js:280:12)
at Connection.g (events.js:291:16)
at emitTwo (events.js:106:13)
at Connection.emit (events.js:191:7)
at Socket.<anonymous> (....\node_modules\mongodb-core\lib\connection\connection.js:187:49)
at Socket.g (events.js:291:16)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at emitErrorNT (net.js:1281:8)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)
name: 'MongoError',
message: 'failed to connect to server [192.168.99.2:27027] on first connect [MongoError: connect ETIMEDOUT 192.168.99.2:27027]' }
I am using the exact same server information used on the datastore.
So what could be wrong here?
And as important: is it possible to use the global Sails connection pool instead of creating a new connection? How? I have searched the documentation but cannot find specific references.
Code was wrong -- using port 27027, while it should be 27017.
Datastore connection worked because of a correct fallback I didn't notice
Try this
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect("mongodb://localhost:27017/test", function(err, db) {
test.equal(null, err);
test.ok(db != null);
});
Ref : here
This question already has answers here:
Cloud Functions for Firebase - getaddrinfo ENOTFOUND
(5 answers)
Closed 5 years ago.
I am attempting to create my first Google Home Action as with the same functinality of my Amazon Alexa Skill. The way this action works is, you execute an intent, and that calls a function in my code. When the function is called, it sends off a GET to an external API to pull some data.
Now when I run this locally using: firebase serve --only functions and ngrok. These will allow me to test the function on API.AI and it works fine.
But when I decide to deploy this to firebase using: firebase deploy --only functions, it simply does not work and throws this error:
error: { RequestError: Error: getaddrinfo EAI_AGAIN newsapi.org:443
at new RequestError (/user_code/node_modules/request-promise/node_modules/request-promise-core/lib/errors.js:14:15)
at Request.plumbing.callback (/user_code/node_modules/request-promise/node_modules/request-promise-core/lib/plumbing.js:87:29)
at Request.RP$callback [as _callback] (/user_code/node_modules/request-promise/node_modules/request-promise-core/lib/plumbing.js:46:31)
at self.callback (/user_code/node_modules/request/request.js:188:22)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at Request.onRequestError (/user_code/node_modules/request/request.js:884:8)
at emitOne (events.js:96:13)
at ClientRequest.emit (events.js:188:7)
at TLSSocket.socketErrorListener (_http_client.js:310:9)
at emitOne (events.js:96:13)
at TLSSocket.emit (events.js:188:7)
at connectErrorNT (net.js:1020:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)
name: 'RequestError',
message: 'Error: getaddrinfo EAI_AGAIN newsapi.org:443',
cause:
{ Error: getaddrinfo EAI_AGAIN newsapi.org:443
at Object.exports._errnoException (util.js:1026:11)
at errnoException (dns.js:33:15)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
code: 'EAI_AGAIN',
errno: 'EAI_AGAIN',
syscall: 'getaddrinfo',
hostname: 'newsapi.org',
host: 'newsapi.org',
port: 443 },
error:
{ Error: getaddrinfo EAI_AGAIN newsapi.org:443
at Object.exports._errnoException (util.js:1026:11)
at errnoException (dns.js:33:15)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
code: 'EAI_AGAIN',
errno: 'EAI_AGAIN',
syscall: 'getaddrinfo',
hostname: 'newsapi.org',
host: 'newsapi.org',
port: 443 },
options:
{ uri: 'https://newsapi.org/v1/articles?source=hacker-news&sortBy=top&apiKey=8b87b4978b22493cadeb351cce01d52a',
headers: { 'User-Agent': 'Request-Promise' },
family: 4,
json: true,
callback: [Function: RP$callback],
transform: undefined,
simple: true,
resolveWithFullResponse: false,
transform2xxOnly: false },
response: undefined }
I cannot seem to find any reason why this would not work, as I can test it locally and get the data by hitting the same URL that is used in the request. In this example, I am using request-promise to complete the request, but I have also used the libraries: got, request, and https.
How can I overcome this problem?
The only thing that I found for this could be that I am not using a paid Firebase plan
I have a very strange error happening.
I am running Node.js version 8.0.0 on Mac OS X Sierra.
I create a very simple http server that basically returns 'ok' to any request after 8 seconds in this example.
I then use the 'request' package to make a request to my http server every 9 seconds, and use the parameter 'forever' to keep the http session alive.
One request out of two works perfectly fine while the other out of two returns a 'socket hang up' error.
Here is the very simple code to reproduce the issue:
const http = require('http');
const request = require('request');
const port = 3000;
const server = http.createServer((req, res) => {
console.log('request');
setTimeout(() => {
res.end('ok');
}, 8000);
});
server.listen(port);
setInterval(() => {
request(`http://localhost:${port}/`, {forever: true}, (error, response, body) => {
if (error) return console.log('error', error);
console.log('done', body);
});
}, 9000);
When I run this code I get the following output on my Macbook Pro :
request
done ok
request
error { Error: socket hang up
at createHangUpError (_http_client.js:343:15)
at Socket.socketOnEnd (_http_client.js:435:23)
at emitNone (events.js:110:20)
at Socket.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1045:12)
at _combinedTickCallback (internal/process/next_tick.js:102:11)
at process._tickCallback (internal/process/next_tick.js:161:9) code: 'ECONNRESET' }
request
done ok
request
error { Error: socket hang up
at createHangUpError (_http_client.js:343:15)
at Socket.socketOnEnd (_http_client.js:435:23)
at emitNone (events.js:110:20)
at Socket.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1045:12)
at _combinedTickCallback (internal/process/next_tick.js:102:11)
at process._tickCallback (internal/process/next_tick.js:161:9) code: 'ECONNRESET' }
request
done ok
request
error { Error: socket hang up
at createHangUpError (_http_client.js:343:15)
at Socket.socketOnEnd (_http_client.js:435:23)
at emitNone (events.js:110:20)
at Socket.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1045:12)
at _combinedTickCallback (internal/process/next_tick.js:102:11)
at process._tickCallback (internal/process/next_tick.js:161:9) code: 'ECONNRESET' }
So I get an 'socket hang up' error exactly every other request.
It seems that the error does not seem to appear on an Ubuntu VPS though.
Any ideas as to why this issue is happening ?
I have the follow backend Node.js code to connect to my Stripe account to make a Charge. But I'm getting this error. I'm using Firebase Functions, and this functionality used to work before, so I doubt this is anything to do with Firebase access restrictions. Any ideas and help on this will be greatly appreciated!
var functions = require('firebase-functions');
var stripe = require('stripe')('sk_test');
var express = require('express');
var bodyParser = require('body-parser');
var cors = require('cors');
exports.stripePay = functions.https.onRequest((request, response) => {
if (request.method === 'POST') {
var app = express();
var router = express.Router();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cors());
var stripetoken = request.body.cardToken;
var amountpayable = request.body.amount;
var charge = stripe.charges.create({
amount: amountpayable,
currency: 'usd',
source: stripetoken,
description: 'Sample transaction'
}, function (err, charge) {
console.log("ST4");
if (err) {
response.send("Failed!");
}
else {
response.send({ success: true });
}
})
}
{ Error: An error occurred with our connection to Stripe
at Error._Error (/user_code/node_modules/stripe/lib/Error.js:12:17)
at Error.Constructor (/user_code/node_modules/stripe/lib/utils.js:98:13)
at Error.Constructor (/user_code/node_modules/stripe/lib/utils.js:98:13)
at ClientRequest.<anonymous> (/user_code/node_modules/stripe/lib/StripeResource.js:192:9)
at emitOne (events.js:96:13)
at ClientRequest.emit (events.js:188:7)
at TLSSocket.socketErrorListener (_http_client.js:310:9)
at emitOne (events.js:96:13)
at TLSSocket.emit (events.js:188:7)
at connectErrorNT (net.js:1020:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9) type: 'StripeConnectionError', stack: 'Error: An error occurred with our connection to Stripe\n at Error._Error (/user_code/node_modules/stripe/lib/Error.js:12:17)\n at Error.Constructor (/user_code/node_modules/stripe/lib/utils.js:98:13)\n at Error.Constructor (/user_code/node_modules/stripe/lib/utils.js:98:13)\n at ClientRequest.<anonymous> (/user_code/node_modules/stripe/lib/StripeResource.js:192:9)\n at emitOne (events.js:96:13)\n at ClientRequest.emit (events.js:188:7)\n at TLSSocket.socketErrorListener (_http_client.js:310:9)\n at emitOne (events.js:96:13)\n at TLSSocket.emit (events.js:188:7)\n at connectErrorNT (net.js:1020:8)\n at _combinedTickCallback (internal/process/next_tick.js:74:11)\n at process._tickDomainCallback (internal/process/next_tick.js:122:9)', rawType: undefined, code: undefined, param: undefined, message: 'An error occurred with our connection to Stripe', detail: { Error: getaddrinfo ENOTFOUND api.stripe.com api.stripe.com:443
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'api.stripe.com',
host: 'api.stripe.com',
port: '443' }, raw: { message: 'An error occurred with our connection to Stripe',
detail:
{ Error: getaddrinfo ENOTFOUND api.stripe.com api.stripe.com:443
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'api.stripe.com',
host: 'api.stripe.com',
port: '443' } }, requestId: undefined, statusCode: undefined } Reply
this is a good one! Firebase blocks external API connections for Free accounts, just get any paid account and this will work!
Dimitris answer is correct, in more layman's terms simply get on the blaze plan and you can make calls to stripe api from Firebase Functions.