Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.1.0] The server responded with a non 2xx status code #700

Closed
4 tasks done
binbard opened this issue Jul 25, 2024 · 5 comments
Closed
4 tasks done

[10.1.0] The server responded with a non 2xx status code #700

binbard opened this issue Jul 25, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@binbard
Copy link

binbard commented Jul 25, 2024

Steps to reproduce


import { ClientType, Innertube, UniversalCache, Utils } from 'youtubei.js';
import { existsSync, mkdirSync, createWriteStream } from 'fs';

(async () => {
  const yt = await Innertube.create({ cache: new UniversalCache(false), generate_session_locally: true, client_type: ClientType.DESKTOP, request_options: { headers: { 'user-agent': 'Mozilla/5.0' } } });

  const songId = 'tLTHjpxTV4c'
  const stream = await yt.download(songId, {
    type: 'audio', // audio, video or video+audio
    quality: 'best', // best, bestefficiency, 144p, 240p, 480p, 720p and so on.
    format: 'mp4' // media container format 
  });

  console.info(`Downloading (${songId})`);

  const dir = `./mysongs`;

  if (!existsSync(dir)) {
    mkdirSync(dir);
  }

  const file = createWriteStream(`${dir}/${songId}.m4a`);

  for await (const chunk of Utils.streamToIterable(stream)) {
    file.write(chunk);
  }

  console.info(`${songId} - Done!`, '\n');
})();

Failure Logs

file:///D:/doe/try/my/yt2/node_modules/youtubei.js/dist/src/utils/FormatUtils.js:61
                            throw new InnertubeError('The server responded with a non 2xx status code', { error_type: 'FETCH_FAILED', response });
                                  ^

InnertubeError: The server responded with a non 2xx status code
    at Module.<anonymous> (file:///D:/doe/try/my/yt2/node_modules/youtubei.js/dist/src/utils/FormatUtils.js:61:35)
    at Generator.next (<anonymous>)
    at fulfilled (D:\doe\try\my\yt2\node_modules\tslib\tslib.js:166:62)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  info: {
    error_type: 'FETCH_FAILED',
    response: Response {
      [Symbol(realm)]: null,
      [Symbol(state)]: {
        aborted: false,
        rangeRequested: false,
        timingAllowPassed: true,
        requestIncludesCredentials: true,
        type: 'default',
        status: 403,
        timingInfo: {
          startTime: 2261.644,
          redirectStartTime: 0,
          redirectEndTime: 0,
          postRedirectStartTime: 2261.644,
          finalServiceWorkerStartTime: 0,
          finalNetworkResponseStartTime: 0,
          finalNetworkRequestStartTime: 0,
          endTime: 2324.2184,
          encodedBodySize: 0,
          decodedBodySize: 0,
          finalConnectionTimingInfo: null
        },
        cacheState: '',
        statusText: 'Forbidden',
        headersList: HeadersList {
          cookies: null,
          [Symbol(headers map)]: Map(13) {
            'last-modified' => [Object],
            'content-type' => [Object],
            'content-length' => [Object],
            'connection' => [Object],
            'access-control-allow-origin' => [Object],
            'access-control-allow-credentials' => [Object],
            'timing-allow-origin' => [Object],
            'access-control-expose-headers' => [Object],
            'vary' => [Object],
            'cross-origin-resource-policy' => [Object],
            'x-content-type-options' => [Object],
            'date' => [Object],
            'server' => [Object]
          },
          [Symbol(headers map sorted)]: null
        },
        urlList: [ URL {} ],
        body: {
          stream: ReadableStream {
            [Symbol(kType)]: 'ReadableStream',
            [Symbol(kState)]: [Object],
            [Symbol(nodejs.webstream.isClosedPromise)]: [Object],
            [Symbol(nodejs.webstream.controllerErrorFunction)]: [Function: bound error]
          }
        }
      },
      [Symbol(headers)]: Headers {
        [Symbol(guard)]: 'immutable',
        [Symbol(headers list)]: HeadersList {
          cookies: null,
          [Symbol(headers map)]: Map(13) {
            'last-modified' => [Object],
            'content-type' => [Object],
            'content-length' => [Object],
            'connection' => [Object],
            'access-control-allow-origin' => [Object],
            'access-control-allow-credentials' => [Object],
            'timing-allow-origin' => [Object],
            'access-control-expose-headers' => [Object],
            'vary' => [Object],
            'cross-origin-resource-policy' => [Object],
            'x-content-type-options' => [Object],
            'date' => [Object],
            'server' => [Object]
          },
          [Symbol(headers map sorted)]: null
        },
        [Symbol(realm)]: null
      }
    }
  },
  date: 2024-07-25T11:47:17.548Z,
  version: '10.1.0'
}

Node.js v20.15.0

Expected behavior

Should have downloaded

Current behavior

Not downloading only can list

Version

Default

Anything else?

"youtubei.js": "^10.1.0"

Checklist

  • I am running the latest version.
  • I checked the documentation and found no answer.
  • I have searched the existing issues and made sure this is not a duplicate.
  • I have provided sufficient information.
@binbard binbard added the bug Something isn't working label Jul 25, 2024
@LuanRT LuanRT closed this as completed Jul 25, 2024
@binbard
Copy link
Author

binbard commented Jul 25, 2024

@LuanRT What is the problem?
Is it specific to me?

@LuanRT
Copy link
Owner

LuanRT commented Jul 25, 2024

@binbard
This has already been fixed. Please see #688.

@twicer-is-coder
Copy link

twicer-is-coder commented Jul 30, 2024

This issue is not fixed. Still happening in 10.2.0.

@LuanRT
Copy link
Owner

LuanRT commented Jul 30, 2024

If it's still happening, then feel free to open a new issue. This one is most likely unrelated to whatever is happening now (YouTube blocking your IPs, expecting attestation tokens, etc).

@stri8ed
Copy link

stri8ed commented Sep 18, 2024

Noticed this error was caused by using type: 'audio'. When I change to video+audio, it works fine. It seems attempting to download audio track results in a 403, when client is set to WEB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants