chatgpt-api icon indicating copy to clipboard operation
chatgpt-api copied to clipboard

getting a 403 Forbidden error when use version 2.2

Open dong706 opened this issue 1 year ago • 5 comments

Hello, I am now getting a 403 Forbidden error when use chatgpt-api version 2.2.

After modify demo-conversation.ts file's api paramter, run it,then throw exception as below:

(node:6860) ExperimentalWarning: The Fetch API is an experimental feature. This
feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
ChatGPTError: ChatGPT failed to refresh auth token. Error: 403 Forbidden
    at ChatGPTAPI.refreshAccessToken (c:\Users\Administrator\Desktop\TestChatGPT
\chatgpt-api-main (1)\src\chatgpt-api.ts:342:21)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5
)
    at ChatGPTAPI.ensureAuth (c:\Users\Administrator\Desktop\TestChatGPT\chatgpt
-api-main (1)\src\chatgpt-api.ts:264:12)
    at main (c:\Users\Administrator\Desktop\TestChatGPT\chatgpt-api-main (1)\dem
os\demo-conversation.ts:36:3) {
  response: Response {
    [Symbol(realm)]: null,
    [Symbol(state)]: {
      aborted: false,
      rangeRequested: false,
      timingAllowPassed: true,
      requestIncludesCredentials: true,
      type: 'default',
      status: 403,
      timingInfo: [Object],
      cacheState: '',
      statusText: 'Forbidden',
      headersList: [HeadersList],
      urlList: [Array],
      body: [Object]
    },
    [Symbol(headers)]: HeadersList {
      [Symbol(headers map)]: [Map],
      [Symbol(headers map sorted)]: null
    }
  },
  statusCode: 403,
  statusText: 'Forbidden',
  originalError: ChatGPTError: 403 Forbidden
      at <anonymous> (c:\Users\Administrator\Desktop\TestChatGPT\chatgpt-api-mai
n (1)\src\chatgpt-api.ts:298:25)
      at process.processTicksAndRejections (node:internal/process/task_queues:95
:5)
      at ChatGPTAPI.refreshAccessToken (c:\Users\Administrator\Desktop\TestChatG
PT\chatgpt-api-main (1)\src\chatgpt-api.ts:292:19)
      at ChatGPTAPI.ensureAuth (c:\Users\Administrator\Desktop\TestChatGPT\chatg
pt-api-main (1)\src\chatgpt-api.ts:264:12)
      at main (c:\Users\Administrator\Desktop\TestChatGPT\chatgpt-api-main (1)\d
emos\demo-conversation.ts:36:3) {
    response: Response {
      [Symbol(realm)]: null,
      [Symbol(state)]: [Object],
      [Symbol(headers)]: [HeadersList]
    },
    statusCode: 403,
    statusText: 'Forbidden'
  }
}

and my demo-conversation.ts as below

import dotenv from 'dotenv-safe'
import { oraPromise } from 'ora'

import { ChatGPTAPI } from '../src'
import { getOpenAIAuthInfo } from './openai-auth-puppeteer'

//dotenv.config()

/**
 * Demo CLI for testing conversation support.
 *
 * ```
 * npx tsx src/demo-conversation.ts
 * ```
 */
async function main() {
  //const email = process.env.EMAIL
  //const password = process.env.PASSWORD

/*
  const authInfo = await getOpenAIAuthInfo({
    email,
    password
  })

  const api = new ChatGPTAPI({ ...authInfo })
  */
  const api = new ChatGPTAPI({
  sessionToken: "**my sessionToken*",
  clearanceToken: "IGIXGUiyKUrNckUjBZ.NiGTOYn7bKjjfmRDYAmU8aXQ-1670850561-0-160",
  userAgent: 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36' // needs to match your browser's user agent
})

  
  
  await api.ensureAuth()

  const conversation = api.getConversation()

  const prompt = 'What is OpenAI?'

  const response = await oraPromise(conversation.sendMessage(prompt), {
    text: prompt
  })

  console.log(response)

  const prompt2 = 'Did they made OpenGPT?'

  console.log(
    await oraPromise(conversation.sendMessage(prompt2), {
      text: prompt2
    })
  )

  const prompt3 = 'Who founded this institute?'

  console.log(
    await oraPromise(conversation.sendMessage(prompt3), {
      text: prompt3
    })
  )

  const prompt4 = 'Who is that?'

  console.log(
    await oraPromise(conversation.sendMessage(prompt4), {
      text: prompt4
    })
  )
}

main().catch((err) => {
  console.error(err)
  process.exit(1)
})

dong706 avatar Dec 12 '22 14:12 dong706