【问题标题】:RequestError: Error: read ECONNRESET nodejsRequestError:错误:读取 ECONNRESET nodejs
【发布时间】:2018-06-13 12:08:11
【问题描述】:

我尝试使用 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) 在 _combinedTickCallback (内部/进程/next_tick.js:138:11) 在 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) 在 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) 在 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 在 在 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);
}

【问题讨论】:

    标签: node.js api request-promise


    【解决方案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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-16
      • 2019-09-12
      • 1970-01-01
      • 2019-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多