agentic
agentic copied to clipboard
getting a 403 Forbidden error when use version 2.2
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)
})
I got the same error too
I'm guessing you logged in to a different ip than the one you used,because I have a similar problem,proxies are not currently supported,if you want try
process.env.http_proxy = 'http://192.168.10.106:8118';
process.env.https_proxy = 'http://192.168.10.106:8118';
const httpAgent = require('https-proxy-agent');
const nodeFetch = require('node-fetch');
globalThis.fetch = function fetch(...args) {
const [url, options = {}] = args;
const proxyOption = {
agent: new httpAgent('http://192.168.10.106:8118'),
...options
};
return nodeFetch(url, proxyOption);
};
I'm guessing you logged in to a different ip than the one you used,because I have a similar problem,proxies are not currently supported,if you want try
process.env.http_proxy = 'http://192.168.10.106:8118'; process.env.https_proxy = 'http://192.168.10.106:8118'; const httpAgent = require('https-proxy-agent'); const nodeFetch = require('node-fetch'); globalThis.fetch = function fetch(...args) { const [url, options = {}] = args; const proxyOption = { agent: new httpAgent('http://192.168.10.106:8118'), ...options }; return nodeFetch(url, proxyOption); };
I try it,but also can not work well,And the exception info as before .Thanks!
For anyone trying to get this to work and struggling:
- Make sure you're using Node.js >= 18
- Make sure your IP address and user agent match exactly the browser that's being used to generate the CF token and session tokens
- Make sure you're using your local install of Chrome and not the default
puppeteer
executable (which Cloudflare detects) - Make sure you're not using the account in a browser window at the same time (since it can invalidate your bot's credentials)
- The clearance token expires every 2 hours; make sure you're refreshing it at least every hour or so
The latest release includes a puppeteer-based solution to automate login. Still TODO is automating potential CAPTCHAS.
I've also improved the docs quite a bit, so hopefully it'll be easier to follow now. Please let me know if you have suggestions / feedback.
https://github.com/transitive-bullshit/chatgpt-api/releases/tag/v2.3.0
I was having the same issue but it only exists in Chrome. I tried with Brave and it's working fine. Chrome tab was open and using it somewhere else getting 403. When using Brave it's working fine, no 403.
Problem might be valid in other browsers like Firefox, Safari etc. I didn't tried them but working fine when you get your token from Brave browser, anyone having that issue, fyi.
I was having the same issue but it only exists in Chrome. I tried with Brave and it's working fine. Chrome tab was open and using it somewhere else getting 403. When using Brave it's working fine, no 403.
Problem might be valid in other browsers like Firefox, Safari etc. I didn't tried them but working fine when you get your token from Brave browser, anyone having that issue, fyi.
I tried this advice with a Brave browser and still got error 403 (Version 2.3.0)
I was having the same issue but it only exists in Chrome. I tried with Brave and it's working fine. Chrome tab was open and using it somewhere else getting 403. When using Brave it's working fine, no 403. Problem might be valid in other browsers like Firefox, Safari etc. I didn't tried them but working fine when you get your token from Brave browser, anyone having that issue, fyi.
Interesting; it's working for me on Chrome, but I've heard at least one other person mention the same issue you experienced with Chrome. They switched browsers and it started working fine.
If you're still struggling with 403 errors, please see my post here: https://github.com/transitive-bullshit/chatgpt-api/issues/96#issuecomment-1350275343
Closing in favor of more focused issues with more context; See Please triple check everything in this comment: https://github.com/transitive-bullshit/chatgpt-api/issues/96#issuecomment-1350275343 for details.