RequestError:错误:读取ECONNRESET nodejs

时间:2018-01-03 19:17:25

标签: node.js api request-promise

我尝试使用nba.com api,但是给我错误。

  

" RequestError:错误:读取ECONNRESET       在新的RequestError(c:\ Users \ Omer \ Desktop \ game \ node_modules \ request-promise-core \ lib \ errors.js:14:15)       在Request.plumbing.callback(c:\ Users \ Omer \ Desktop \ game \ node_modules \ request-promise-core \ lib \ plumbing.js:87:29)       在Request.RP $ callback [as _callback](c:\ Users \ Omer \ Desktop \ game \ node_modules \ request-promise-core \ lib \ plumbing.js:46:31)       在self.callback(c:\ Users \ Omer \ Desktop \ game \ node_modules \ request \ request.js:188:22)       在emitOne(events.js:116:13)       在Request.emit(events.js:211:7)       在Request.onRequestError(c:\ Users \ Omer \ Desktop \ game \ node_modules \ request \ request.js:884:8)       在emitOne(events.js:116:13)       在ClientRequest.emit(events.js:211:7)       在TLSSocket.socketErrorListener(_http_client.js:387:9)       在emitOne(events.js:116:13)       在TLSSocket.emit(events.js:211:7)       在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)   从以前的事件:       在Request.plumbing.init(c:\ Users \ Omer \ Desktop \ game \ node_modules \ request-promise-core \ lib \ plumbing.js:36:28)       在Request.RP $ initInterceptor [as init](c:\ Users \ Omer \ Desktop \ game \ node_modules \ request-promise-core \ configure \ request2.js:41:27)       在新请求(c:\ Users \ Omer \ Desktop \ game \ node_modules \ request \ request.js:130:8)       根据要求(c:\ Users \ Omer \ Desktop \ game \ node_modules \ request \ index.js:54:10)       at requestStats(c:\ Users \ Omer \ Desktop \ game \ modules \ utils \ crawlers \ stats \ nba.stats.crawler.js:23:12)       在Object.crawl(c:\ Users \ Omer \ Desktop \ game \ modules \ utils \ crawlers \ stats \ nba.stats.crawler.js:12:12)       在Object.crawl(c:\ Users \ Omer \ Desktop \ game \ modules \ utils \ crawlers \ stats \ stats.crawler.js:20:20)       at Object.runCrawl(c:\ Users \ Omer \ Desktop \ game \ modules \ utils \ crawlers \ utils.crawler.js:27:18)       在startCrawl(c:\ Users \ Omer \ Desktop \ game \ scripts \ useful \ crawl.js:19:13)       在loadConfig(c:\ Users \ Omer \ Desktop \ game \ scripts \ useful \ crawl.js:12:5)       在c:\ Users \ Omer \ Desktop \ game \ config \ lib \ mongoose.js:35:21       在       at process._tickCallback(internal / process / next_tick.js:188:7)"

我的代码:

    var path = require('path'),
    request = require('request-promise'),
    format = require('string-template');

module.exports = {
    crawl: crawl
};

const STATS_NBA_API = 'http://stats.nba.com/stats/leaguegamelog?Counter=1000&DateFrom=&DateTo=&Direction=DESC&LeagueID=00&PlayerOrTeam=P&Season=2017-18&SeasonType=Regular+Season&Sorter=DATE';

function crawl(options){
    return requestStats(STATS_NBA_API)
        .then(statsPlayers => { return convertStatsToList(statsPlayers); })
        .catch(error => 
            console.log(error))
}

function convertStatsToList(statsPlayers){
    console.log(statsPlayers)
}

function requestStats(url){
    var options = {
        method: 'GET',
        url: url,
        json: true       
    };
    return request(options);
}

1 个答案:

答案 0 :(得分:1)

   function requestStats(url) {
    var options = {
        method: 'GET',
        url: url,
        json: true,
        headers: {
            'Connection': 'keep-alive',
            'Accept-Encoding': '',
            'Accept-Language': 'en-US,en;q=0.8'
        }
    };
    return request(options);
}
相关问题