I have this code:
request('http://www.nytimes.com/2015/10/04/upshot/soda-industry-struggles-as-consumer-tastes-change.html', function (err, resp, body) {
if (err) {
console.error(err);
}
});
if get this error:
(node) warning: possible EventEmitter memory leak detected. 11 pipe listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at Request.addListener (events.js:179:15)
at Request.init (/Users/amills001c/WebstormProjects/underscore/alleyoop/node_modules/request/request.js:496:8)
at Redirect.onResponse (/Users/amills001c/WebstormProjects/underscore/alleyoop/node_modules/request/lib/redirect.js:149:11)
at Request.onRequestResponse (/Users/amills001c/WebstormProjects/underscore/alleyoop/node_modules/request/request.js:944:22)
at ClientRequest.emit (events.js:107:17)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:426:21)
at HTTPParser.parserOnHeadersComplete (_http_common.js:111:23)
at Socket.socketOnData (_http_client.js:317:20)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
(node) warning: possible EventEmitter memory leak detected. 11 end listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at Request.addListener (events.js:179:15)
at Request.start (/Users/amills001c/WebstormProjects/underscore/alleyoop/node_modules/request/request.js:843:8)
at Request.end (/Users/amills001c/WebstormProjects/underscore/alleyoop/node_modules/request/request.js:1394:10)
at end (/Users/amills001c/WebstormProjects/underscore/alleyoop/node_modules/request/request.js:564:14)
at Immediate._onImmediate (/Users/amills001c/WebstormProjects/underscore/alleyoop/node_modules/request/request.js:578:7)
at processImmediate [as _immediateCallback] (timers.js:367:17)
[Error: Exceeded maxRedirects. Probably stuck in a redirect loop http://www.nytimes.com/2015/10/04/upshot/soda-industry-struggles-as-consumer-tastes-change.html?_r=4]
I don't see a redirect loop, so any idea what it could be? thanks
It seems that nytimes.com generates infinite loop of redirects with cookies disabled, so you need to enable them when make the request:
request({
url: 'http://www.nytimes.com/2015/10/04/upshot/soda-industry-struggles-as-consumer-tastes-change.html',
jar: true
}, function (err, resp, body) {
});
That fixes the issue idd, thanks for the help, @calibr :+1:
That fixes the issue. Thanks @calibr
If you're coming to this from Google and cookie jars don't fix your issue (or you don't want them) read https://github.com/request/request/issues/3139 to figure out why this happened and how to fix it.
Most helpful comment
It seems that nytimes.com generates infinite loop of redirects with cookies disabled, so you need to enable them when make the request: