agentic icon indicating copy to clipboard operation
agentic copied to clipboard

ChatGPTError: Failed to authenticate session [sourcePort:443]

Open zangguojun opened this issue 2 years ago • 6 comments

Verify latest release

  • [X] I verified that the issue exists in the latest chatgpt release

Verify webapp is working

  • [X] I verify that the ChatGPT webapp is working properly for this account.

Environment details

NodeJS v18.13.0 MacOS 12.6

Describe the Bug

I am trying to run the first demo (https://github.com/transitive-bullshit/chatgpt-api#demos) , but get 403 and error Here is log when running cmds npx tsx demos/demo.ts

request {
  url: 'https://chat.openai.com/api/auth/session',
  method: 'GET',
  headers: {
    'sec-ch-ua': '"Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108"',
    referer: 'https://chat.openai.com/auth/login',
    'sec-ch-ua-mobile': '?0',
    'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36',
    'sec-ch-ua-platform': '"macOS"'
  },
  body: undefined
}

response {
  url: 'https://chat.openai.com/api/auth/session',
  ok: true,
  status: 200,
  statusText: '',
  headers: {
    'alt-svc': 'h3=":443"; ma=86400, h3-29=":443"; ma=86400',
    'cf-cache-status': 'DYNAMIC',
    'cf-ray': '7861ad93ac2f097a-HKG',
    'content-length': '2',
    'content-type': 'application/json; charset=utf-8',
    date: 'Sun, 08 Jan 2023 02:59:35 GMT',
    etag: '"bwc9mymkdm2"',
    server: 'cloudflare',
    'set-cookie': '__Host-next-auth.csrf-token=963760c9e1fd9cf8284def87538a50b29c4534bbeb0cacefe658a21f34cc00da%7Cec3d67132a50a7d3f73d24e4a768b4899dfb0879384c12fc4676243afc9f62b5; Path=/; HttpOnly; Secure; SameSite=Lax\n' +
      '__Secure-next-auth.callback-url=https%3A%2F%2Fchat.openai.com; Path=/; HttpOnly; Secure; SameSite=Lax',
    'strict-transport-security': 'max-age=15724800; includeSubDomains',
    'x-client-source': 'explorer'
  },
  body: {},
  request: {
    method: 'GET',
    headers: {
      'sec-ch-ua': '"Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108"',
      referer: 'https://chat.openai.com/auth/login',
      'sec-ch-ua-mobile': '?0',
      'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36',
      'sec-ch-ua-platform': '"macOS"'
    },
    body: undefined
  }
}
chatgpt [email protected] auth {
  userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36',
  clearanceToken: 'xxxi6_I6dsGsc3s5ocYrVaa5rntGgfMorjZyGeIMxQ-1673146774-0-1-4a825b6.6c7fxxxxxx,
  sessionToken: undefined,
  cookies: {
    __cf_bm: {
      name: '__cf_bm',
      value: '6xxx.2eUsZakzB6lX7CCPLZidr1N48bRvaF4M-1673146923-0-AVfWi4lBSkidL/5IStpBIgUlDwJIf6bRwwLqyfxZXYYUSpTkTuoHPw47dYsasaht5eSB2/yIAlI+kAmfxxx=',
      domain: '.chat.openai.com',
      path: '/',
      expires: 1673148723.509978,
      size: 152,
      httpOnly: true,
      secure: true,
      session: false,
      sameSite: 'None',
      sameParty: false,
      sourceScheme: 'Secure',
      sourcePort: 443
    },
    '__Secure-next-auth.callback-url': {
      name: '__Secure-next-auth.callback-url',
      value: 'https%3A%2F%2Fchat.openai.com%2F',
      domain: 'chat.openai.com',
      path: '/',
      expires: -1,
      size: 63,
      httpOnly: true,
      secure: true,
      session: true,
      sameSite: 'Lax',
      sameParty: false,
      sourceScheme: 'Secure',
      sourcePort: 443
    },
    '__Host-next-auth.csrf-token': {
      name: '__Host-next-auth.csrf-token',
      value: 'xxx60c9e1fd9cf8284def87538a50b29c4534bbeb0cacefe658a21f34cc00da%7Cec3d67132a50a7d3f73d24e4a768b4899dfb0879384c12fc4676243afc9f62xxx',
      domain: 'chat.openai.com',
      path: '/',
      expires: -1,
      size: 158,
      httpOnly: true,
      secure: true,
      session: true,
      sameSite: 'Lax',
      sameParty: false,
      sourceScheme: 'Secure',
      sourcePort: 443
    },
    '__Secure-next-auth.state': {
      name: '__Secure-next-auth.state',
      value: 'xxxxxkaXIiLCJlbmMiOiJBMjU2R0NNIn0..hpolI41McAd5fTit.xbNtH_Y02bbiC5nFotr2b7o7Lg9CdjskGIHtoU-SsMKVAZgBBfUu5g5l07YKpuC_OYEaVdovsJ_pMpEpUzaybBWYC9oYmH4e6A0oCUtTY1C64dgJD1hZKN8Lq-k4Ep_v4q0zFmTn3gTdnacYKfaD6ZeaHqCTvpC1E9rQW6JtyymdfriH9Ew.PzXtXeKC_NTPgSxfjxxxxxx',
      domain: 'chat.openai.com',
      path: '/',
      expires: 1673147677.910293,
      size: 284,
      httpOnly: true,
      secure: true,
      session: false,
      sameSite: 'Lax',
      sameParty: false,
      sourceScheme: 'Secure',
      sourcePort: 443
    },
    cf_chl_2: {
      name: 'cf_chl_2',
      value: 'xxxf8d2a74fxxxx',
      domain: 'chat.openai.com',
      path: '/',
      expires: 1673150523,
      size: 23,
      httpOnly: false,
      secure: false,
      session: false,
      sameParty: false,
      sourceScheme: 'Secure',
      sourcePort: 443
    },
    _cfuvid: {
      name: '_cfuvid',
      value: 'xxxzEYteP3bAylLIHosceTBokwu5429ZKA.MItlIs8-1673146775163-0-xxxxx',
      domain: '.chat.openai.com',
      path: '/',
      expires: -1,
      size: 76,
      httpOnly: true,
      secure: true,
      session: true,
      sameSite: 'None',
      sameParty: false,
      sourceScheme: 'Secure',
      sourcePort: 443
    },
    '__Secure-next-auth.pkce.code_verifier': {
      name: '__Secure-next-auth.pkce.code_verifier',
      value: 'xxxxOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..jMUaEDjw4QD5_KS5.F6mAkZOsgli2f0GRz1KEGizE2ESuR7_YL7hA3bsloDnDxNSo99gRsSPeRjIKop5OidIC73bpCQ-ik2OspUpC5mOsIQol3P3zPmWV5p42QNNzYTbPvXnCAmfDvSdlvj3XaWVkesOJmKs45pPpgrrJh1rml2lYqKVr2Uj_ZQn0c6lR8Y3GecAVFdAvpodcWg.VgvmceW03dl-xxxxx',
      domain: 'chat.openai.com',
      path: '/',
      expires: 1673147677.91038,
      size: 308,
      httpOnly: true,
      secure: true,
      session: false,
      sameSite: 'Lax',
      sameParty: false,
      sourceScheme: 'Secure',
      sourcePort: 443
    },
    cf_clearance: {
      name: 'cf_clearance',
      value: 'syBqi6_I6dsGsc3s5ocYrVaa5rntGgfMorjZyGeIMxQ-1673146774-0-1-4a825b6.6c7f921f.53a97a56-160',
      domain: '.chat.openai.com',
      path: '/',
      expires: 1704682774.223701,
      size: 100,
      httpOnly: true,
      secure: true,
      session: false,
      sameSite: 'None',
      sameParty: false,
      sourceScheme: 'Secure',
      sourcePort: 443
    }
  }
}
ChatGPTError: Failed to authenticate session
    at ChatGPTAPIBrowser.initSession (/xx/chatgpt-api/src/chatgpt-api-browser.ts:210:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at main (/xx/chatgpt-api/demos/demo.ts:28:13)

zangguojun avatar Jan 08 '23 03:01 zangguojun

Having the same issue, but inside my dockerized container which can't seem to get past authentication. Saw some thoughts about it being a geo issue, but not sure if that's the problem. I've tried to approve the IP/browser location already from Google security, so would expect those issues to be gone already as well. Not sure how to proceed.

karam-khanna avatar Jan 08 '23 14:01 karam-khanna

@zangguojun are you running this with headful chromium? What's going on in the browser? I'm not seeing the 403 in your logs.

The main issue seems to be that sessionToken is undefined.

transitive-bullshit avatar Jan 10 '23 10:01 transitive-bullshit

@zangguojun are you running this with headful chromium? What's going on in the browser? I'm not seeing the 403 in your logs.

The main issue seems to be that sessionToken is undefined.

Yes, I just clone the project, enter the Correct email and password in .env.example, and then run npx tsx demos/demo.ts. I don't know the reason for the error, but it seems that many people have similar errors.

zangguojun avatar Jan 11 '23 12:01 zangguojun

/chatgpt/build/index.js

        await page.waitForSelector('input[type="password"]', { visible: true });
        await page.type('input[type="password"]', password);
        await delay(50);
        submitP = () => page.keyboard.press("Enter");

I think we should wait for 2fa auth to continue here, @zangguojun maybe you should disable 2fa in your account

reconka avatar Jan 29 '23 14:01 reconka

Try upgrading to the latest version; we're now using the official API, and you should no longer have any auth issues or rate limiting: https://github.com/transitive-bullshit/chatgpt-api/releases/tag/v4.0.0

transitive-bullshit avatar Feb 01 '23 12:02 transitive-bullshit

Machine translation: Yes, I have also encountered this in docker, and can only get over the limit through 'proxyServer'. May be able to see me do this example: https://github.com/bincooo/webgpt-bot.git

bincooo avatar Feb 03 '23 10:02 bincooo