mpociot / chatgpt-vscode

A VSCode extension that allows you to use ChatGPT

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: ChatGPT failed to refresh auth token: 403 forbidden

KristjanDeepX opened this issue · comments

Looks like the extension is currently broken due to downstream issues.
transitive-bullshit/chatgpt-api#96

i got the Same Error. i tried it with diffrent session tokens. :(

This error is due to additional CloudFlare protection added by OpenAI, however it can be circumvented (with limitations) by extracting three parameters from the web version (instead of just sessionToken) as described here.

I have this implemented in my fork, and have also already published the updated version to the VSCode Marketplace, so if you only want to use the extension just update it and enter the new parameters as described in the readme.md.

Hope this helps!

This error is due to additional CloudFlare protection added by OpenAI, however it can be circumvented (with limitations) by extracting three parameters from the web version (instead of just sessionToken) as described here.

I have this implemented in my fork, and have also already published the updated version to the VSCode Marketplace, so if you only want to use the extension just update it and enter the new parameters as described in the readme.md.

Hope this helps!

I followed these steps and am still getting the 403

@hsavit1 @timkmecl Same here. Followed all the steps outlined and I'm still getting 403. Made sure the session token, clearance token, and user agent were properly filled in, but same 403 error.

Huh that's weird. I just retested it and it still works fine here. I am usingEdge on Windows 10, and my user-agent is Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.46.
Would you mind sharing your OS, browser and user-agent to see if we can determine the cause of the issue?

Huh that's weird. I just retested it and it still works fine here. I am usingEdge on Windows 10, and my user-agent is Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.46. Would you mind sharing your OS, browser and user-agent to see if we can determine the cause of the issue?

Still getting 403 error. For user-agent, did you put Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.46 or 108.0.0.0?

The whole text, i.e. Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.46 (but make sure you use your own, not just copy mine)

This error is due to additional CloudFlare protection added by OpenAI, however it can be circumvented (with limitations) by extracting three parameters from the web version (instead of just sessionToken) as described here.
I have this implemented in my fork, and have also already published the updated version to the VSCode Marketplace, so if you only want to use the extension just update it and enter the new parameters as described in the readme.md.
Hope this helps!

I followed these steps and am still getting the 403

in my case, I use Fedora 37. I did the Cloudflare steps but it still continues with the problems I pointed out earlier. It works normally directly on the Chat GPT website.

Could you please check what node version you have installed (node -v)?
There may be a problem with chatgpt-api for versions<18

Could you please check what node version you have installed (node -v)? There may be a problem with chatgpt-api for versions<18

image

Could you tell me which browser you use? And maybe paste your user-agent

I'm also still having the issue , using @timkmecl fork, I'm on Chrome , my user-agent is Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36

I just retested it using Chrome (previously I was on Edge) and it works too. Honestly I have currently no idea why it works for some and not for the others, if anyone knows something or finds out a solution either for the users or for me to implement please let me know!

Could you tell me which browser you use? And maybe paste your user-agent

image

TBH my use case could be not really reflecting other users, I'm trying to get the extension work with GitPod (gitpod.io) :)

This is the request send (stripped out my tokens) :

accept
: 
"*/*"
accept-language
: 
"en-US,en;q=0.9"
cookie
: 
"cf_clearance=removed; __Secure-next-auth.session-token=removed"
origin
: 
"https://chat.openai.com"
referer
: 
"https://chat.openai.com/chat"
sec-ch-ua
: 
"\"Not?A_Brand\";v=\"8\", \"Chromium\";v=\"108\", \"Google Chrome\";v=\"108\""
sec-ch-ua-platform
: 
"\"macOS\""
sec-fetch-dest
: 
"empty"
sec-fetch-mode
: 
"cors"
sec-fetch-site
: 
"same-origin"
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"
x-openai-assistant-app-id
: 
""

In chat.openai.com I see other cookies being passed like __Host-next-auth.csrf-token...

I also just tested with my VS Code and same issue

just tried it after upgrading everything still getting error 403

Could you tell me which browser you use? And maybe paste your user-agent

image

image

Version 108.0.5359.99 (Official Build) (64-bit)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36

I will paste my answer from my fork here which shows some new info:

It looks like this problem is not limited to this project, but also to some other ones using chatgpt-api, probably caused by agressive CloudFlare protection. In my own testing, even when I tried to login to my account in Chrome right after using it inside Edge, I got a 403 error inside the web version. After I waited for several minutes and tried again, it disappeard, but this shows that the problem is not just with the javascript API.

The browser that you use for getting the tokens might influence the chance to get 403, especially chrome, so maybe try from another one (transitive-bullshit/chatgpt-api#107 (comment))

There might also be some account or IP flagging going on either by OpenAI or CloudFlare that increases the possibility of getting 403 especially if doing lots of requests often (transitive-bullshit/chatgpt-api#96 (comment))

I am currently working on upgrading the login method for the extension to include an option to login using email and password, which will hopefully help solve this, will update you all then. In the meantime, if anyone learns something new about this, feel free to post it here!

Update:

It seems like using Chrome to obtain the tokens is what is causing (most of?) these issues (see this, this). So if you have 403 Error despite following the instructions, try using a browser other than Chrome!

I will update the README to include this info.

It looks like this problem is not limited to this project, but also to some other ones using chatgpt-api, probably caused by agressive CloudFlare protection. In my own testing, even when I tried to login to my account in Chrome right after using it inside Edge, I got a 403 error inside the web version. After I waited for several minutes and tried again, it disappeard, but this shows that the problem is not just with the javascript API.

The browser that you use for getting the tokens might influence the chance to get 403, especially Chrome, so maybe try from another one (transitive-bullshit/chatgpt-api#107 (comment))

There might also be some account or IP flagging going on either by OpenAI or CloudFlare that increases the possibility of getting 403 especially if doing lots of requests often (transitive-bullshit/chatgpt-api#96 (comment))

I am currently working on upgrading the login method for the extension to include an option to login using email and password, which will hopefully help solve this, will update you all then. In the meantime, if anyone learns something new about this, feel free to post it here!

I downloaded just for this the Opera GX Browser and now it works. The Session-token seems to be the same but what was defnitly diffrent is the "cf_clearance" token and slightly the "userAgent" but it just looks like a diffrent Version of Chrome

Great, then it seems like using Chrome to obtain the tokens is what is causing (most of?) these issues.

So if you have 403 Error despite following the instructions, try using a browser other than Chrome!

I will update the README to include this info.

I can confirm that the token generated with Opera GX works with my VS Code (not yet with gitpod but I will get there :) )

Had no success with neither Microsoft Edge, nor Opera GX, getting 403s.
Maybe this has something to do with VS Code running under WSL2 that messes with IP addressing, maybe not.

@kirsanium Doubtful. Same issue here and I'm running on MacOS.

Is it possible that this might have something to do with an Ad Blocker or being behind a PiHole setup?

This the new error that I'm getting [ERROR] Error: ChatGPT failed to refresh auth token. TypeError: Cannot convert argument to a ByteString because the character at index 112 has a value of 65279 which is greater than 255. I tryed every browser and they all failed and I disabled my Adblock and it didn't make any difference.

Still no go with AdGaurd disabled.

Not working for me even using Opera GX :( It looks like there is a new version of https://github.com/transitive-bullshit/chatgpt-api that uses a browser-based authentication method, I wonder if that might work here?

commented

Not working same 403...

Not working for me even using Opera GX :( It looks like there is a new version of https://github.com/transitive-bullshit/chatgpt-api that uses a browser-based authentication method, I wonder if that might work here?

@coffenbacher I am experimenting this on my extension here: https://marketplace.visualstudio.com/items?itemName=gencay.vscode-chatgpt. It's somewhat a custom solution since the chatgpt-api browser based solution doesn't work in vs-code out of the box.

It uses the browser-based solution and without any token copy-pastes. Just make sure to keep the Chrome instance open while querying the chatgpt via the extension (It will be automatically minimized after successful login). You can in fact use any chromium based browser, you just need to overwrite it within the settings. It's described here.

Awesome work @gencay ! That is working for me.

Not working for me even using Opera GX :( It looks like there is a new version of https://github.com/transitive-bullshit/chatgpt-api that uses a browser-based authentication method, I wonder if that might work here?

@coffenbacher I am experimenting this on my extension here: https://marketplace.visualstudio.com/items?itemName=gencay.vscode-chatgpt. It's somewhat a custom solution since the chatgpt-api browser based solution doesn't work in vs-code out of the box.

It uses the browser-based solution and without any token copy-pastes. Just make sure to keep the Chrome instance open while querying the chatgpt via the extension (It will be automatically minimized after successful login). You can in fact use any chromium based browser, you just need to overwrite it within the settings. It's described here.

Works charm's here too. Thanks a \o/ @gencay
I take a look at the plugin it's yours. Great Work buddy!

it's weired. among my three computers, ChatGPT for google works on two, and fails on one, which runs Windows 7 Flagship version, where Chrome could not be updated. I think the issue "Please login and pass Cloudflare check at chat.openai.com" has something to do with Chrome version.

You can try my other extension CodeGPT (Marketplace link) based on this one, which uses a different method to connect to ChatGPT (it does however not support real-time streaming of the response, and conversation/follow up questions are not yet implemented). You only need an official OpanAI API key, no need to deal with session tokens or having Chrome open.

This all should no longer be a problem as of today. The latest version on the VSCode Marketplace now uses the newly released official API! Source code in my repo.

Hi @timkmecl , I still getting error same as above, event I download new version