sportsdataverse / sportsdataverse-js

Retrieves sports data from a popular sports website as well as from the NCAA website, with support for NBA, WNBA, NFL, NHL, College Football and mens and womens college basketball,
https://js.sportsdataverse.org
49 stars 12 forks source link

Issue pulling NCAAB Scores #1

Closed jaredwheet closed 3 years ago

jaredwheet commented 3 years ago

Hi, this is a great package and really hoping to use it to gather ncaa basketball scores for an app. I am running into an issue, and I cannot seem to resolve it. Here is my code

const sdv = require("sportsdataverse");

async function getScores() {
  try {
    const inputs = {
      year: 2021,
      month: 02,
      day: 15,
    };
    const result = await sdv.cbbScoreboard.getScoreboard(inputs);
    console.log(result);
  } catch (e) {
    console.log(e);
  }
}

getScores();

When i run node index.js I am getting an error - output below. Cant seem to fix this, was wondering if you can help dissect why this error is occuring?


Error: Request failed with status code 400
    at createError (C:\Users\jared\OneDrive\Documents\score_scraper\node_modules\axios\lib\core\createError.js:16:15)
    at settle (C:\Users\jared\OneDrive\Documents\score_scraper\node_modules\axios\lib\core\settle.js:17:12)
    at Unzip.handleStreamEnd (C:\Users\jared\OneDrive\Documents\score_scraper\node_modules\axios\lib\adapters\http.js:260:11)
    at Unzip.emit (events.js:315:20)
    at endReadableNT (internal/streams/readable.js:1327:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  config: {
    url: 'http://site.api.espn.com/apis/site/v2/sports/basketball/mens-college-basketball/scoreboard',
    method: 'get',
    headers: {
      Accept: 'application/json, text/plain, */*',
      'User-Agent': 'axios/0.21.1'
    },
    params: { dates: '2021215', group: 50, seasontype: null, limit: 1000 },
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    adapter: [Function: httpAdapter],
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    validateStatus: [Function: validateStatus],
    data: undefined
  },
  request: <ref *1> ClientRequest {
    _events: [Object: null prototype] {
      socket: [Function (anonymous)],
      abort: [Function (anonymous)],
      aborted: [Function (anonymous)],
      connect: [Function (anonymous)],
      error: [Function (anonymous)],
      timeout: [Function (anonymous)],
      prefinish: [Function: requestOnPrefinish]
    },
    _eventsCount: 7,
    _maxListeners: undefined,
    outputData: [],
    outputSize: 0,
    writable: true,
    destroyed: true,
    _last: true,
    chunkedEncoding: false,
    shouldKeepAlive: false,
    _defaultKeepAlive: true,
    useChunkedEncodingByDefault: false,
    sendDate: false,
    _removedConnection: false,
    _removedContLen: false,
    _removedTE: false,
    _contentLength: 0,
    _hasBody: true,
    _trailer: '',
    finished: true,
    _headerSent: true,
    socket: Socket {
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: 'site.api.espn.com',
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 6,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: null,
      _server: null,
      parser: null,
      _httpMessage: [Circular *1],
      [Symbol(async_id_symbol)]: 2,
      [Symbol(kHandle)]: null,
      [Symbol(kSetNoDelay)]: false,
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: null,
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kCapture)]: false,
      [Symbol(kBytesRead)]: 551,
      [Symbol(kBytesWritten)]: 230,
      [Symbol(RequestTimeout)]: undefined
    },
    _header: 'GET /apis/site/v2/sports/basketball/mens-college-basketball/scoreboard?dates=2021215&group=50&limit=1000 HTTP/1.1\r\n' +
      'Accept: application/json, text/plain, */*\r\n' +
      'User-Agent: axios/0.21.1\r\n' +
      'Host: site.api.espn.com\r\n' +
      'Connection: close\r\n' +
      '\r\n',
    _keepAliveTimeout: 0,
    _onPendingData: [Function: noopPendingOutput],
    agent: Agent {
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      defaultPort: 80,
      protocol: 'http:',
      options: [Object],
      requests: {},
      sockets: {},
      freeSockets: {},
      keepAliveMsecs: 1000,
      keepAlive: false,
      maxSockets: Infinity,
      maxFreeSockets: 256,
      scheduling: 'fifo',
      maxTotalSockets: Infinity,
      totalSocketCount: 0,
      [Symbol(kCapture)]: false
    },
    socketPath: undefined,
    method: 'GET',
    maxHeaderSize: undefined,
    insecureHTTPParser: undefined,
    path: '/apis/site/v2/sports/basketball/mens-college-basketball/scoreboard?dates=2021215&group=50&limit=1000',
    _ended: true,
    res: IncomingMessage {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 1,
      _maxListeners: undefined,
      socket: [Socket],
      httpVersionMajor: 1,
      httpVersionMinor: 1,
      httpVersion: '1.1',
      complete: true,
      headers: [Object],
      rawHeaders: [Array],
      trailers: {},
      rawTrailers: [],
      aborted: false,
      upgrade: false,
      url: '',
      method: null,
      statusCode: 400,
      statusMessage: 'Bad Request',
      client: [Socket],
      _consuming: false,
      _dumped: false,
      req: [Circular *1],
      responseUrl: 'http://site.api.espn.com/apis/site/v2/sports/basketball/mens-college-basketball/scoreboard?dates=2021215&group=50&limit=1000',
      redirects: [],
      [Symbol(kCapture)]: false,
      [Symbol(RequestTimeout)]: undefined
    },
    aborted: false,
    timeoutCb: null,
    upgradeOrConnect: false,
    parser: null,
    maxHeadersCount: null,
    reusedSocket: false,
    host: 'site.api.espn.com',
    protocol: 'http:',
    _redirectable: Writable {
      _writableState: [WritableState],
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      _options: [Object],
      _ended: true,
      _ending: true,
      _redirectCount: 0,
      _redirects: [],
      _requestBodyLength: 0,
      _requestBodyBuffers: [],
      _onNativeResponse: [Function (anonymous)],
      _currentRequest: [Circular *1],
      _currentUrl: 'http://site.api.espn.com/apis/site/v2/sports/basketball/mens-college-basketball/scoreboard?dates=2021215&group=50&limit=1000',
      [Symbol(kCapture)]: false
    },
    [Symbol(kCapture)]: false,
    [Symbol(kNeedDrain)]: false,
    [Symbol(corked)]: 0,
    [Symbol(kOutHeaders)]: [Object: null prototype] {
      accept: [Array],
      'user-agent': [Array],
      host: [Array]
    }
  },
  response: {
    status: 400,
    statusText: 'Bad Request',
    headers: {
      'content-type': 'application/json;charset=UTF-8',
      'content-length': '73',
      pragma: 'no-cache',
      'access-control-allow-origin': '*',
      'access-control-allow-methods': 'GET,PUT,POST,DELETE,OPTIONS,HEAD',
      'access-control-expose-headers': 'content-length,location',
      link: '<scoreboard.json#>; rel="describedby"',
      vary: 'Accept-Encoding',
      'cache-control': 'max-age=1',
      expires: 'Tue, 23 Feb 2021 22:09:45 GMT',
      date: 'Tue, 23 Feb 2021 22:09:44 GMT',
      connection: 'close'
    },
    config: {
      url: 'http://site.api.espn.com/apis/site/v2/sports/basketball/mens-college-basketball/scoreboard',
      method: 'get',
      headers: [Object],
      params: [Object],
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      adapter: [Function: httpAdapter],
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      validateStatus: [Function: validateStatus],
      data: undefined
    },
    request: <ref *1> ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: true,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: 0,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      socket: [Socket],
      _header: 'GET /apis/site/v2/sports/basketball/mens-college-basketball/scoreboard?dates=2021215&group=50&limit=1000 HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'User-Agent: axios/0.21.1\r\n' +
        'Host: site.api.espn.com\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: noopPendingOutput],
      agent: [Agent],
      socketPath: undefined,
      method: 'GET',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      path: '/apis/site/v2/sports/basketball/mens-college-basketball/scoreboard?dates=2021215&group=50&limit=1000',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'site.api.espn.com',
      protocol: 'http:',
      _redirectable: [Writable],
      [Symbol(kCapture)]: false,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype]
    },
    data: { code: 400, message: 'Failed to get events endpoint.' }
  },
  isAxiosError: true,
  toJSON: [Function: toJSON]
}
saiemgilani commented 3 years ago

I think I did a bad job of defining the parameters. This is literally my first node project. I think your code should work, it looks like how I expect the function to work. Give it a day for me to figure out the issue

saiemgilani commented 3 years ago

This should now work without issues as far as I can tell as of v1.0.7, apparently groups is non-negotiable. Also, seasontype = 2 is regular season, 3 is post-season, 4 is offseason, 1 is pre-season

const inputs = {
      group: 50,
      year: 2021,
      month: 02,
      day: 15
    };
    const result = await sdv.cbbScoreboard.getScoreboard(inputs);

Let me know if that change helps fix your issue so I can close it.

jaredwheet commented 3 years ago

thanks for quickly looking at it. It still seems to give me the bad request.

Error: Request failed with status code 400
    at createError (C:\Users\jared\OneDrive\Documents\score_scraper\node_modules\axios\lib\core\createError.js:16:15)
    at settle (C:\Users\jared\OneDrive\Documents\score_scraper\node_modules\axios\lib\core\settle.js:17:12)
    at Unzip.handleStreamEnd (C:\Users\jared\OneDrive\Documents\score_scraper\node_modules\axios\lib\adapters\http.js:260:11)
    at Unzip.emit (events.js:315:20)
    at endReadableNT (internal/streams/readable.js:1327:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  config: {
    url: 'http://site.api.espn.com/apis/site/v2/sports/basketball/mens-college-basketball/scoreboard',
    method: 'get',
    headers: {
      Accept: 'application/json, text/plain, */*',
      'User-Agent': 'axios/0.21.1'
    },
    params: { dates: '2021215', group: 50, seasontype: 2, limit: 1000 },
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    adapter: [Function: httpAdapter],
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    validateStatus: [Function: validateStatus],
    data: undefined
  },

Is there a good place to find docs on the espnAPI? I am having a hard time finding a resource that is clear on what params are required

saiemgilani commented 3 years ago

https://gist.github.com/akeaswaran/b48b02f1c94f873c6655e7129910fc3b

if you're so inclined, you can come hang out with us in the cfbscrapR discord (a related cfb project where we discuss code and such)

https://discord.gg/46QV57g7

jaredwheet commented 3 years ago

very cool, im gonna jump in there and see if we can figure it out - and looking forward to seeing what else you guys are up to

saiemgilani commented 3 years ago

we all gang gang now. issue fixed by #9c429cea