xtekky / gpt4free

The official gpt4free repository | various collection of powerful language models
https://g4f.ai
GNU General Public License v3.0
60.18k stars 13.23k forks source link

Arkoke token not found in .har file #2087

Closed Baldi89989 closed 2 weeks ago

Baldi89989 commented 3 months ago

Bug description When using open ai chat, i get a error saying "no arkose token found in .har file" while i used a .har file. How do i fix it?

Screenshots image

Environment Python version: 3.12.1 Location: France

phamxtien commented 3 months ago

I got the same

Lorodn4x commented 3 months ago

I got the same

gamelist1990 commented 3 months ago

I just tried it and it works fine.

gamelist1990 commented 3 months ago

Obtaining the HAR file from ChatGPT

Here's a method to obtain the HAR (HTTP Archive) file from ChatGPT:

  1. Access ChatGPT: Go to https://chatgpt.com/.
  2. Open Network Tab: Open your browser's developer tools and navigate to the "Network" tab.
  3. Send a Request: Interact with the AI by sending a message. Ensure you see a response in the Network tab, indicating a successful request.
  4. Open New Chat: Click on "New Chat" to start a fresh conversation.
  5. Check Request Count: Observe the request count in the Network tab. If successful, the count should be approximately between 93 and 104.

At this point, you can right-click on any of the requests and select "Save as HAR" to download the HAR file.

Note: The exact request count may vary slightly depending on the specific interaction and browser used.

Lorodn4x commented 3 months ago

Obtaining the HAR file from ChatGPT

Here's a method to obtain the HAR (HTTP Archive) file from ChatGPT:

  1. Access ChatGPT: Go to https://chatgpt.com/.
  2. Open Network Tab: Open your browser's developer tools and navigate to the "Network" tab.
  3. Send a Request: Interact with the AI by sending a message. Ensure you see a response in the Network tab, indicating a successful request.
  4. Open New Chat: Click on "New Chat" to start a fresh conversation.
  5. Check Request Count: Observe the request count in the Network tab. If successful, the count should be approximately between 93 and 104.

At this point, you can right-click on any of the requests and select "Save as HAR" to download the HAR file.

Note: The exact request count may vary slightly depending on the specific interaction and browser used.

where should I put this file?

gamelist1990 commented 3 months ago

from g4f.client import Client

cookies_dir = os.path.join(os.path.dirname(__file__), "har_and_cookies")

client=Client(api_key=read_cookie_files(cookies_dir))

response = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[{"role": "user", "content": "Hello"}],

)
print(response.choices[0].message.content)

In the case of a code like this, just put the har in the "har_and_cookies" folder

Baldi89989 commented 3 months ago

Is there rate limits? (Because i’m recreating clyde in discord and users spam my bot)

GlitchOwl commented 3 months ago

Same problem. Able to get 2 answers from gpt before getting this error. I have a free account.

Found this in my har file:

f={[c.PT.PAID]:\"35536E1E-65B4-4D96-9D97-6ADB7EFF8147\",[c.PT.FREEACCOUNT]:\"3D86FBBA-9D22-402A-B512-3420086BA6CC\",[c.PT.NOAUTH]:\"BD7D7B66-1476-42B2-A6BE-095F3BB4DF2D\",[d.SUBSCRIPTION]:\"8E3CED7F-F5EA-43D0-A5C3-745D29FDCFBC\"};

However in har_file.py:

arkPreURL = "https://tcr9i.chat.openai.com/fc/gt2/public_key/35536E1E-65B4-4D96-9D97-6ADB7EFF8147"

Tried replacing 35536E1E-65B4-4D96-9D97-6ADB7EFF8147 with 3D86FBBA-9D22-402A-B512-3420086BA6CC, now it parses correctly, but i had to comment lines 118 and 119 in order for it to work.

I think it solves the problem? Now i get mostly Cloudflare errors. Sometimes i get "Our systems have detected unusual activity coming from your system. Please try again later." error. Is it related?

Note: i use a proxy

Actions i made while recording har file:

  1. visited https://chatgpt.com
  2. logged out
  3. logged in
  4. sent a request to chatgpt
  5. waited for response
  6. clicked on "new chat"
  7. sent a request again
  8. solved captcha
  9. stopped recording
GlitchOwl commented 2 months ago

Looks like "Our systems have detected unusual activity coming from your system. Please try again later." is related to this issue. Arkose token is probably wrong. Im getting good responses when arkose token is not required, but i think it fails every time chatgpt needs one. There is a chance that OpenAI have changed something again. Can anyone confirm?

@gamelist1990 are u sure u r actually using arkose tokens? g4f.debug.logging = True to check If so, u probably have a Plus account. Can u try the same script with a free plan account?

gamelist1990 commented 2 months ago

Sorry, I haven't used OpenAIChat for a while, so I don't know how it works at the moment.

gamelist1990 commented 2 months ago

ChatGPT Reverse Engineering Update: Adapting to Arkose Detection Changes

These instructions correspond to recent changes in the ChatGPT backend.

Problem:

Previously, the code relied on checking the requirements["arkose"]["required"] flag to determine if an Arkose token was necessary. However, ChatGPT has adjusted its API, and this information is now nested within a text key within the requirements object. This change breaks the existing Arkose detection logic.

Solution:

This modification the create_async_generator function to correctly interpret the updated Arkose detection mechanism.

Here's how the code is updated:

Original code:

                   as response:
                    cls._update_request_args(session)
                    await raise_for_status(response)
                    requirements = await response.json()
                    need_arkose = requirements.get("arkose", {}).get("required")
                    chat_token = requirements["token"]      

Updated code:

                    as response:
                    cls._update_request_args(session)
                    await raise_for_status(response)
                    requirements = await response.json()
                    #Get from text
                    text_data = json.loads(requirements.get("text", "{}")) 
                    need_arkose = text_data.get("turnstile", {}).get("required", False)
                    if need_arkose:
                        arkose_token = text_data.get("turnstile", {}).get("dx")
                    else:
                        need_arkose = requirements.get("arkose", {}).get("required", False) 
                    chat_token = requirements["token"]

Instead of directly accessing requirements["arkose"], the updated code:

  1. Retrieves the data from the text key and parses it as JSON.
  2. Checks for the presence of the turnstile key within the parsed JSON.
  3. If turnstile exists, it further checks if the required flag is set to True.
  4. If the required flag is True, the Arkose token is extracted from the dx key within turnstile.
  5. For backward compatibility, it also checks the old arkose key in case it's still present.

This change ensures that the code can adapt to both the old and new API responses, allowing it to accurately detect Arkose challenges and proceed with the authentication process.

gamelist1990 commented 2 months ago

I hope this fix helps

gamelist1990 commented 2 months ago

Is there rate limits? (Because i’m recreating clyde in discord and users spam my bot)

There is a possibility of rate limiting, but I think it is unlikely

phamxtien commented 2 months ago

today i got Response 403: Cloudflare detected

gamelist1990 commented 2 months ago

Is it the same no matter how many times you do it?

@phamxtien

gamelist1990 commented 2 months ago

Using OpenaiChat provider and auto model

Arkose: False Proofofwork: gAAAAABWzI1M...
INFO:    192.168.128:0 - "GET /chat?provider=OpenAI&prompt=%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF&system=&token=AI74bf652f-7de6-43eb-a592-42c5ff233d52 HTTP/1.1" 200 OK 

It's working normally in the log of my environment If you are blocked many times, please recreate the har file.

phamxtien commented 2 months ago

Is it the same no matter how many times you do it?

@phamxtien

I think it causes by the network, now it runs smooth with another network.

gamelist1990 commented 2 months ago

let's see how it goes for a bit and let me know if there's anything else.

GlitchOwl commented 2 months ago

@gamelist1990 nice fix!!! But the "No arkose token found in .har file" error still occurs.

If you change arkPreURL like i did in the message before, you get this

05:47:40
Using OpenaiChat provider and gpt-3.5-turbo model
Arkose: 53817e0ba123... Proofofwork: gAAAAABwQ8Lk...
Retry: Error 403: {"detail":"Unusual activity has been detected from your device. Try again later. (8a0d3b09afe09e04-EWR)"}
Arkose: 53817e0ba123... Proofofwork: gAAAAABwQ8Lk...
Retry: Error 403: {"detail":"Unusual activity has been detected from your device. Try again later. (8a0d3b7f68919e04-EWR)"}
Arkose: False Proofofwork: gAAAAABWzI0M...
*prints response* - finally! 

It looks like arkose check fails every time. You can see that i get a response only when "Arkose: False". Can anyone confirm? If the issue is hard to reproduce, try using a proxy

Is "Error 403: Unusual activity has been detected from your device" error related to arkose? Note: "Response 403: Cloudflare detected" is the other error and is not related to this issue. Is arkose token required for gpt3.5?

I guess we have to figure out why openai detects unusual activity and also fix the way script parses the har file.

gamelist1990 commented 2 months ago

https://github.com/xtekky/gpt4free/issues/2092

As mentioned here, the API may have changed.

@GlitchOwl

gamelist1990 commented 2 months ago

By the way, I tried to fix that just now, but it failed spectacularly (^^)

gamelist1990 commented 2 months ago

It looks like arkose check fails every time. You can see that i get a response only when "Arkose: False". Can anyone confirm? If the issue is hard to reproduce, try using a proxy

Is "Error 403: Unusual activity has been detected from your device" error related to arkose? Note: "Response 403: Cloudflare detected" is the other error and is not related to this issue. Is arkose token required for gpt3.5?

I guess we have to figure out why openai detects unusual activity and also fix the way script parses the har file.

I think this kind of thing is happening a lot because OpenAI updated and no longer uses Arkose.

phamxtien commented 2 months ago

I get .har from Edge Browser >> It runs ok But with .har from Firefox >> It returns 403

github-actions[bot] commented 2 months ago

Bumping this issue because it has been open for 7 days with no activity. Closing automatically in 7 days unless it becomes active again.

iG8R commented 2 months ago

up

github-actions[bot] commented 2 months ago

Bumping this issue because it has been open for 7 days with no activity. Closing automatically in 7 days unless it becomes active again.

iG8R commented 2 months ago

up

github-actions[bot] commented 1 month ago

Bumping this issue because it has been open for 7 days with no activity. Closing automatically in 7 days unless it becomes active again.

iG8R commented 1 month ago

up

github-actions[bot] commented 1 month ago

Bumping this issue because it has been open for 7 days with no activity. Closing automatically in 7 days unless it becomes active again.

iG8R commented 1 month ago

up

github-actions[bot] commented 1 month ago

Bumping this issue because it has been open for 7 days with no activity. Closing automatically in 7 days unless it becomes active again.

iG8R commented 1 month ago

up

github-actions[bot] commented 1 month ago

Bumping this issue because it has been open for 7 days with no activity. Closing automatically in 7 days unless it becomes active again.

AppSolves commented 1 month ago

@gamelist1990 How is it going? #2105

gamelist1990 commented 1 month ago

I'm sorry, I completely forgot

gamelist1990 commented 1 month ago

I'll take a look when I can this week

phamxtien commented 1 month ago

It runs smooth for me

github-actions[bot] commented 3 weeks ago

Bumping this issue because it has been open for 7 days with no activity. Closing automatically in 7 days unless it becomes active again.

github-actions[bot] commented 2 weeks ago

Closing due to inactivity.