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

Error: ChatGPT failed to refresh auth token: 403 forbidden

Open KristjanDeepX opened this issue 1 year ago • 39 comments

Looks like the extension is currently broken due to downstream issues. https://github.com/transitive-bullshit/chatgpt-api/issues/96

KristjanDeepX avatar Dec 11 '22 22:12 KristjanDeepX

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

AlphaKevin24 avatar Dec 12 '22 13:12 AlphaKevin24

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!

timkmecl avatar Dec 12 '22 16:12 timkmecl

Same here. Screenshot from 2022-12-12 17-04-08 Screenshot from 2022-12-12 17-04-28

thiagolucio avatar Dec 12 '22 20:12 thiagolucio

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 avatar Dec 13 '22 00:12 hsavit1

@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.

eshack94 avatar Dec 13 '22 05:12 eshack94

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?

timkmecl avatar Dec 13 '22 07:12 timkmecl

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?

eddy-the-wang avatar Dec 13 '22 07:12 eddy-the-wang

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)

timkmecl avatar Dec 13 '22 07:12 timkmecl

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.

thiagolucio avatar Dec 13 '22 12:12 thiagolucio

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

timkmecl avatar Dec 13 '22 12:12 timkmecl

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

image

thiagolucio avatar Dec 13 '22 13:12 thiagolucio

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

timkmecl avatar Dec 13 '22 15:12 timkmecl

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

sebastienblanc avatar Dec 13 '22 16:12 sebastienblanc

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!

timkmecl avatar Dec 13 '22 16:12 timkmecl

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

image

thiagolucio avatar Dec 13 '22 16:12 thiagolucio

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...

sebastienblanc avatar Dec 13 '22 16:12 sebastienblanc

I also just tested with my VS Code and same issue

sebastienblanc avatar Dec 13 '22 17:12 sebastienblanc

just tried it after upgrading everything still getting error 403

eod9910 avatar Dec 13 '22 19:12 eod9910

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

image

image

thiagolucio avatar Dec 13 '22 19:12 thiagolucio

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

eod9910 avatar Dec 13 '22 19:12 eod9910

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 (https://github.com/transitive-bullshit/chatgpt-api/issues/107#issuecomment-1349712906)

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 (https://github.com/transitive-bullshit/chatgpt-api/issues/96#issuecomment-1350275343)

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.

timkmecl avatar Dec 14 '22 07:12 timkmecl

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

AlphaKevin24 avatar Dec 14 '22 09:12 AlphaKevin24

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.

timkmecl avatar Dec 14 '22 09:12 timkmecl

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

sebastienblanc avatar Dec 14 '22 10:12 sebastienblanc

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 avatar Dec 15 '22 12:12 kirsanium

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

eshack94 avatar Dec 15 '22 20:12 eshack94

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

eshack94 avatar Dec 15 '22 21:12 eshack94

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.

eod9910 avatar Dec 15 '22 21:12 eod9910

Still no go with AdGaurd disabled.

polarfileio avatar Dec 16 '22 17:12 polarfileio

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 avatar Dec 20 '22 20:12 coffenbacher