xtekky / gpt4free

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

An error occured: OpenaiChat: MissingAuthError: Add a "api_key" or a .har file #2092

Open hodhh8 opened 1 month ago

hodhh8 commented 1 month ago

Screenshot 2024-07-03 210708

gamelist1990 commented 1 month ago

Have you added chatgpt.com.har?

Anurag-Varma commented 1 month ago

Not a bug,

Need to use api key or use a .har file with the cookies from the chatgpt website and keep it in the har_and_cookies folder

imranaalam commented 1 month ago

i was hoping can there be a chrome extension be made that can fetch har and integrate with gpt4free

gamelist1990 commented 1 month ago

I think it's difficult to get it with an extension. @imranaalam

dabatz commented 1 month ago

how can it be fixed then? becuase i dont know how to add the .har file and where. could somone provide a more detailed explenation on how to do it?

gamelist1990 commented 1 month 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.

dabatz commented 1 month ago

@gamelist1990 I did all the steps but it still sends the same error. I downloaded the har file (as "chatgpt.com") and put it in the same directory as the g4f file (C:\Users\user\Downloads\coding related stuff\g4f.exe). did I do something wrong?

P.S. Thanks for the help. Appreciate it.

Anurag-Varma commented 1 month ago

If u downloaded the github repo, you can keep it in the har_and_cookies folder.

Dont know where to keep incase of g4f.exe

dabatz commented 1 month ago

I don't have a har_and_cookies folder, should I create one in the g4f directory?

dabatz commented 1 month ago

ok, I now downloaded it correctly, I think, using "pip install g4f" in cmd. is that ok? if yes what do I do now?

gamelist1990 commented 1 month ago

image I have specified the directory to put the har files in, so it is the har folder, but you can create a separate har_and_cookies folder and put the created har files in that folder. 

cookies_dir = os.path.join(os.path.dirname(file), "har_and_cookies") set_cookies_dir(cookies_dir) read_cookie_files(cookies_dir)

@dabatz

gamelist1990 commented 1 month ago

@dabatz

What should I do in the case of g4f.exe? It doesn't change, but g4f.exe seems to just be running flask internally, so place g4f.exe and the har_and_cookies folder in the directory and put the har file in it.

Lorodn4x commented 1 month ago

Hello, I am using a VPN through WireGuard and it seems that this might be causing an issue with authentication. I have followed all the steps to add the .har file, but the "MissingAuthError: Add a 'api_key' or a .har file" error still appears. Could you please advise what can be done in this situation? Thank you.

iG8R commented 1 month ago

@Lorodn4x Hello. No, it doesn't depend on using a VPN, because even without a VPN this problem still exists.

Lorodn4x commented 1 month ago

@iG8R Thank you for your response. In my country, ChatGPT does not work without a VPN. Even when I follow all the steps using the VPN, I occasionally receive messages stating that the service is not available in my region or something similar. I have encountered this error again and attached a screenshot for further clarification Снимок экрана 2024-07-06 233429

iG8R commented 1 month ago

@Lorodn4x In my country, ChatGPT works fine without VPN, but g4f still gets the error mentioned in this issue.

gamelist1990 commented 1 month ago

Could you please provide the code you're using and where you put the har?

@iG8R @Lorodn4x

iG8R commented 1 month ago

@gamelist1990 Many thanks for your attention and concern.

image

iG8R commented 1 month ago

Also I used your last PR https://github.com/xtekky/gpt4free/commit/fea9e7a198fd21aa22c9ced90977c941c4ceffb6

gamelist1990 commented 1 month ago

It looks like Arkose authentication has passed, but then a 502 error appears

For now, if you get a 502 error even after trying several times, try changing the model to auto or something similar. I use the auto model.

gamelist1990 commented 1 month ago

Also I used your last PR https://github.com/xtekky/gpt4free/commit/fea9e7a198fd21aa22c9ced90977c941c4ceffb6

That fix solved the Arkose issue so it's fine.

iG8R commented 1 month ago

As you can see, not every time I got a 502 error, sometimes there is a "No arkose token found in .har file" error and sometimes there is an "OK" response.

gamelist1990 commented 1 month ago

Can you try the model with auto?

iG8R commented 1 month ago

image

gamelist1990 commented 1 month ago

Umm

iG8R commented 1 month ago

I use the following app and browser extension to make a request to g4f https://github.com/xtekky/gpt4free/issues/1896#issuecomment-2094507543

gamelist1990 commented 1 month ago

I'll take a look.

gamelist1990 commented 1 month ago

I’m not sure if this method will work, but first, please try uninstalling g4f. Next, copy the g4f folder from g4ffree and place it in the directory you are using (probably with the following directory structure): Directory = g4f (folder), main.py (code to run g4f), har_and_cookies (folder)

Please make sure to take a backup before trying.

iG8R commented 1 month ago

Every time with the new version of g4f I make a clean install of it in the following manner https://github.com/xtekky/gpt4free/issues/1896#issuecomment-2094503579

gamelist1990 commented 1 month ago

There seems to be no problem with the setup.

Maybe the problem is that it is placed in the c directory, so you can test it by placing it in the download folder, etc., or try setting the access permissions correctly.

gamelist1990 commented 1 month ago

Just to confirm, do other providers that do not use har such as geminiProChat work?

iG8R commented 1 month ago

Maybe the problem is that it is placed in the c directory, so you can test it by placing it in the download folder, etc., or try setting the access permissions correctly.

The same result:

image

Just to confirm, do other providers that do not use har such as geminiProChat work?

Yes, they are OK.

image

Lorodn4x commented 1 month ago

Could you please provide the code you're using and where you put the har?

@iG8R @gamelist1990

Hello,

Thank you for your prompt response.

Here's what I have done so far:

Created a virtual environment. Installed the g4f package using pip install -U g4f in the same directory. In the same directory, created a folder named har_and_cookies and placed the chatgpt.com.har file in this folder. After this setup, I started encountering the following error:

An error occurred: OpenaiChat: MissingAuthError: No arkose token found in .har file I also tried installing the package directly from the repository, but the same error persists.

Could you please help me identify what might be going wrong?

gamelist1990 commented 1 month ago

Currently pip install is not up to date with the latest version, so I get a No arkose token found in .har file error.

To solve this problem, you can download it with git clone and put har_and_cookies etc. in the directory in which it is downloaded.

gamelist1990 commented 1 month ago

Want to see a sample video? If you want to see it, we'll make one.

gamelist1990 commented 1 month ago

from g4f.client import Client
from g4f.Provider import OpenaiChat
from g4f.cookies import set_cookies_dir, read_cookie_files
import g4f.debug

g4f.debug.logging = True

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

client = Client(
    provider=OpenaiChat,
    cookies=set_cookies_dir(cookies_dir),
)
response = client.chat.completions.create(
    model="auto",
    messages=[{"role": "user", "content": "Hello"}],

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

**Anyone who gets the api_key= error, try this code and let me know the result.**
iG8R commented 1 month ago

@gamelist1990 Thanks a lot for your concern.

Here is the result:

image

OpenaiChat.py

405:                    ) as response:
406:                        cls._update_request_args(session)
407:                        await raise_for_status(response)
408:                        requirements = await response.json()
409:                        text_data = json.loads(requirements.get("text", "{}")) 
410:                        need_arkose = text_data.get("turnstile", {}).get("required", False)
411:                        if need_arkose:
412:                            arkose_token = text_data.get("turnstile", {}).get("dx")
413:                        else:
414:                            need_arkose = requirements.get("arkose", {}).get("required", False) 
415:                        chat_token = requirements["token"]        
416:    
417:                    if need_arkose and arkose_token is None:
418:                        arkose_token, api_key, cookies, headers, proofTokens = await getArkoseAndAccessToken(proxy)
419:                        cls._create_request_args(cookies, headers)
420:                        cls._set_api_key(api_key)
421:                        if arkose_token is None:
422:                            raise MissingAuthError("No arkose token found in .har file")

PS. Please, add import os to your code or else I get the following error:

image

from g4f.client import Client
from g4f.Provider import OpenaiChat
from g4f.cookies import set_cookies_dir, read_cookie_files
import g4f.debug
import os

g4f.debug.logging = True

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

client = Client(
    provider=OpenaiChat,
    cookies=set_cookies_dir(cookies_dir),
)

response = client.chat.completions.create(
    model="auto",
    messages=[{"role": "user", "content": "Hello"}],
)

print(response.choices[0].message.content)
gamelist1990 commented 1 month ago

Sorry I forgot to add import os.

Sorry, OpenAichat seems to be ok, then the problem could be in the har file.

iG8R commented 1 month ago

My .har file contains the following:

image

iG8R commented 1 month ago

The .har file is the newest:

image

gamelist1990 commented 1 month ago

Could you try again with the directory structure of the images you are about to send?

gamelist1990 commented 1 month ago

Please wait a moment.

gamelist1990 commented 1 month ago

image

gamelist1990 commented 1 month ago

See what happens with this directory structure?

iG8R commented 1 month ago

You mean I need only g4f, har (not har_and_cookies?), venv dirs and only 2 files in the main dir?

gamelist1990 commented 1 month ago

I just wanted to know if I could test it with a directory structure and have it talk normally.

iG8R commented 1 month ago

image

gamelist1990 commented 1 month ago

Windows?

iG8R commented 1 month ago

Yes, Microsoft Windows [Version 10.0.19045.2673].

Lorodn4x commented 1 month ago

(venv) C:\Users\admin\Desktop\g4f\gpt4free>python test.py
Read .har file: C:\Users\admin\Desktop\g4f\gpt4free\har_and_cookies\chatgpt.com.har
New g4f version: 0.3.2.1 (current: 0.0.0) | pip install -U g4f
Using OpenaiChat provider and auto model
Traceback (most recent call last):
  File "C:\Users\admin\Desktop\g4f\gpt4free\test.py", line 17, in <module>
    response = client.chat.completions.create(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\client\client.py", line 118, in create
    return response if stream else next(response)
                                   ^^^^^^^^^^^^^^
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\client\client.py", line 57, in iter_append_model_and_provider
    for chunk in response:
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\client\client.py", line 29, in iter_response
    for idx, chunk in enumerate(response):
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\providers\base_provider.py", line 223, in create_completion
    yield loop.run_until_complete(await_callback(gen.__anext__))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\providers\base_provider.py", line 52, in await_callback
    return await callback()
           ^^^^^^^^^^^^^^^^
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\Provider\needs_auth\OpenaiChat.py", line 422, in create_async_generator
    raise MissingAuthError("No arkose token found in .har file")
g4f.errors.MissingAuthError: No arkose token found in .har file

(venv) C:\Users\admin\Desktop\g4f\gpt4free>python test.py
Read .har file: C:\Users\admin\Desktop\g4f\gpt4free\har_and_cookies\chatgpt.com.har
New g4f version: 0.3.2.1 (current: 0.0.0) | pip install -U g4f
Using OpenaiChat provider and auto model
Traceback (most recent call last):
  File "C:\Users\admin\Desktop\g4f\gpt4free\test.py", line 17, in <module>
    response = client.chat.completions.create(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\client\client.py", line 118, in create
    return response if stream else next(response)
                                   ^^^^^^^^^^^^^^
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\client\client.py", line 57, in iter_append_model_and_provider
    for chunk in response:
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\client\client.py", line 29, in iter_response
    for idx, chunk in enumerate(response):
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\providers\base_provider.py", line 223, in create_completion
    yield loop.run_until_complete(await_callback(gen.__anext__))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\providers\base_provider.py", line 52, in await_callback
    return await callback()
           ^^^^^^^^^^^^^^^^
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\Provider\needs_auth\OpenaiChat.py", line 422, in create_async_generator
    raise MissingAuthError("No arkose token found in .har file")
g4f.errors.MissingAuthError: No arkose token found in .har file

(venv) C:\Users\admin\Desktop\g4f\gpt4free>python test.py
Read .har file: C:\Users\admin\Desktop\g4f\gpt4free\har_and_cookies\chatgpt.com.har
New g4f version: 0.3.2.1 (current: 0.0.0) | pip install -U g4f
Using OpenaiChat provider and auto model
Arkose: False Proofofwork: gAAAAABWzMwM...
Hi there! How can I assist you today?

(venv) C:\Users\admin\Desktop\g4f\gpt4free>python test.py
Read .har file: C:\Users\admin\Desktop\g4f\gpt4free\har_and_cookies\chatgpt.com.har
New g4f version: 0.3.2.1 (current: 0.0.0) | pip install -U g4f
Using OpenaiChat provider and auto model
Arkose: False Proofofwork: gAAAAABWzMwM...
Hi there! How can I assist you today?

(venv) C:\Users\admin\Desktop\g4f\gpt4free>python test.py
Read .har file: C:\Users\admin\Desktop\g4f\gpt4free\har_and_cookies\chatgpt.com.har
New g4f version: 0.3.2.1 (current: 0.0.0) | pip install -U g4f
Using OpenaiChat provider and auto model
Arkose: False Proofofwork: gAAAAABwQ8Lk...
Traceback (most recent call last):
  File "C:\Users\admin\Desktop\g4f\gpt4free\test.py", line 17, in <module>
    response = client.chat.completions.create(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\client\client.py", line 118, in create
    return response if stream else next(response)
                                   ^^^^^^^^^^^^^^
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\client\client.py", line 57, in iter_append_model_and_provider
    for chunk in response:
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\client\client.py", line 29, in iter_response
    for idx, chunk in enumerate(response):
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\providers\base_provider.py", line 223, in create_completion
    yield loop.run_until_complete(await_callback(gen.__anext__))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\providers\base_provider.py", line 52, in await_callback
    return await callback()
           ^^^^^^^^^^^^^^^^
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\Provider\needs_auth\OpenaiChat.py", line 479, in create_async_generator
    await raise_for_status(response)
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\requests\raise_for_status.py", line 28, in raise_for_status_async
    raise ResponseStatusError(f"Response {response.status}: {message}")
g4f.errors.ResponseStatusError: Response 502: <html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <style global>body{font-family:Arial,Helvetica,sans-serif}.container{align-items:center;display:flex;flex-direction:column;gap:2rem;height:100%;justify-content:center;width:100%}@keyframes enlarge-appear{0%{opacity:0;transform:scale(75%) rotate(-90deg)}to{opacity:1;transform:scale(100%) rotate(0deg)}}.logo{color:#8e8ea0}.scale-appear{animation:enlarge-appear .4s ease-out}@media (min-width:768px){.scale-appear{height:48px;width:48px}}.data:empty{display:none}.data{border-radius:5px;color:#8e8ea0;max-width:420px;text-align:center;width:100%}.data ul{list-style:none;padding:0}@media (prefers-color-scheme:dark){body{background-color:#343541}.logo{color:#acacbe}}</style>

</head>
  <body>
    <div class="container">
      <div class="logo">
        <svg
          width="41"
          height="41"
          viewBox="0 0 41 41"
          fill="none"
          xmlns="http://www.w3.org/2000/svg"
          strokeWidth="2"
          class="scale-appear"
        >
          <path
            d="M37.5324 16.8707C37.9808 15.5241 38.1363 14.0974 37.9886 12.6859C37.8409 11.2744 37.3934 9.91076 36.676 8.68622C35.6126 6.83404 33.9882 5.3676 32.0373 4.4985C30.0864 3.62941 27.9098 3.40259 25.8215 3.85078C24.8796 2.7893 23.7219 1.94125 22.4257 1.36341C21.1295 0.785575 19.7249 0.491269 18.3058 0.500197C16.1708 0.495044 14.0893 1.16803 12.3614 2.42214C10.6335 3.67624 9.34853 5.44666 8.6917 7.47815C7.30085 7.76286 5.98686 8.3414 4.8377 9.17505C3.68854 10.0087 2.73073 11.0782 2.02839 12.312C0.956464 14.1591 0.498905 16.2988 0.721698 18.4228C0.944492 20.5467 1.83612 22.5449 3.268 24.1293C2.81966 25.4759 2.66413 26.9026 2.81182 28.3141C2.95951 29.7256 3.40701 31.0892 4.12437 32.3138C5.18791 34.1659 6.8123 35.6322 8.76321 36.5013C10.7141 37.3704 12.8907 37.5973 14.9789 37.1492C15.9208 38.2107 17.0786 39.0587 18.3747 39.6366C19.6709 40.2144 21.0755 40.5087 22.4946 40.4998C24.6307 40.5054 26.7133 39.8321 28.4418 38.5772C30.1704 37.3223 31.4556 35.5506 32.1119 33.5179C33.5027 33.2332 34.8167 32.6547 35.9659 31.821C37.115 30.9874 38.0728 29.9178 38.7752 28.684C39.8458 26.8371 40.3023 24.6979 40.0789 22.5748C39.8556 20.4517 38.9639 18.4544 37.5324 16.8707ZM22.4978 37.8849C20.7443 37.8874 19.0459 37.2733 17.6994 36.1501C17.7601 36.117 17.8666 36.0586 17.936 36.0161L25.9004 31.4156C26.1003 31.3019 26.2663 31.137 26.3813 30.9378C26.4964 30.7386 26.5563 30.5124 26.5549 30.2825V19.0542L29.9213 20.998C29.9389 21.0068 29.9541 21.0198 29.9656 21.0359C29.977 21.052 29.9842 21.0707 29.9867 21.0902V30.3889C29.9842 32.375 29.1946 34.2791 27.7909 35.6841C26.3872 37.0892 24.4838 37.8806 22.4978 37.8849ZM6.39227 31.0064C5.51397 29.4888 5.19742 27.7107 5.49804 25.9832C5.55718 26.0187 5.66048 26.0818 5.73461 26.1244L13.699 30.7248C13.8975 30.8408 14.1233 30.902 14.3532 30.902C14.583 30.902 14.8088 30.8408 15.0073 30.7248L24.731 25.1103V28.9979C24.7321 29.0177 24.7283 29.0376 24.7199 29.0556C24.7115 29.0736 24.6988 29.0893 24.6829 29.1012L16.6317 33.7497C14.9096 34.7416 12.8643 35.0097 10.9447 34.4954C9.02506 33.9811 7.38785 32.7263 6.39227 31.0064ZM4.29707 13.6194C5.17156 12.0998 6.55279 10.9364 8.19885 10.3327C8.19885 10.4013 8.19491 10.5228 8.19491 10.6071V19.808C8.19351 20.0378 8.25334 20.2638 8.36823 20.4629C8.48312 20.6619 8.64893 20.8267 8.84863 20.9404L18.5723 26.5542L15.206 28.4979C15.1894 28.5089 15.1703 28.5155 15.1505 28.5173C15.1307 28.5191 15.1107 28.516 15.0924 28.5082L7.04046 23.8557C5.32135 22.8601 4.06716 21.2235 3.55289 19.3046C3.03862 17.3858 3.30624 15.3413 4.29707 13.6194ZM31.955 20.0556L22.2312 14.4411L25.5976 12.4981C25.6142 12.4872 25.6333 12.4805 25.6531 12.4787C25.6729 12.4769 25.6928 12.4801 25.7111 12.4879L33.7631 17.1364C34.9967 17.849 36.0017 18.8982 36.6606 20.1613C37.3194 21.4244 37.6047 22.849 37.4832 24.2684C37.3617 25.6878 36.8382 27.0432 35.9743 28.1759C35.1103 29.3086 33.9415 30.1717 32.6047 30.6641C32.6047 30.5947 32.6047 30.4733 32.6047 30.3889V21.188C32.6066 20.9586 32.5474 20.7328 32.4332 20.5338C32.319 20.3348 32.154 20.1698 31.955 20.0556ZM35.3055 15.0128C35.2464 14.9765 35.1431 14.9142 35.069 14.8717L27.1045 10.2712C26.906 10.1554 26.6803 10.0943 26.4504 10.0943C26.2206 10.0943 25.9948 10.1554 25.7963 10.2712L16.0726 15.8858V11.9982C16.0715 11.9783 16.0753 11.9585 16.0837 11.9405C16.0921 11.9225 16.1048 11.9068 16.1207 11.8949L24.1719 7.25025C25.4053 6.53903 26.8158 6.19376 28.2383 6.25482C29.6608 6.31589 31.0364 6.78077 32.2044 7.59508C33.3723 8.40939 34.2842 9.53945 34.8334 10.8531C35.3826 12.1667 35.5464 13.6095 35.3055 15.0128ZM14.2424 21.9419L10.8752 19.9981C10.8576 19.9893 10.8423 19.9763 10.8309 19.9602C10.8195 19.9441 10.8122 19.9254 10.8098 19.9058V10.6071C10.8107 9.18295 11.2173 7.78848 11.9819 6.58696C12.7466 5.38544 13.8377 4.42659 15.1275 3.82264C16.4173 3.21869 17.8524 2.99464 19.2649 3.1767C20.6775 3.35876 22.0089 3.93941 23.1034 4.85067C23.0427 4.88379 22.937 4.94215 22.8668 4.98473L14.9024 9.58517C14.7025 9.69878 14.5366 9.86356 14.4215 10.0626C14.3065 10.2616 14.2466 10.4877 14.2479 10.7175L14.2424 21.9419ZM16.071 17.9991L20.4018 15.4978L24.7325 17.9975V22.9985L20.4018 25.4983L16.071 22.9985V17.9991Z"
            fill="currentColor"
          />
        </svg>
      </div>
      <div class="data"><div class="cf-error-details cf-error-502">
  <h1>Bad gateway</h1>
  <p>The web server reported a bad gateway error.</p>
  <ul>
    <li>Ray ID: 8a0029ae689b2e0d</li>
    <li>Your IP address: 147.45.76.244</li>
    <li>Error reference number: 502</li>
    <li>Cloudflare Location: Stockholm</li>
  </ul>
</div>
</div>
    </div>
  </body>
</html>

(venv) C:\Users\admin\Desktop\g4f\gpt4free>python test.py
Read .har file: C:\Users\admin\Desktop\g4f\gpt4free\har_and_cookies\chatgpt.com.har
New g4f version: 0.3.2.1 (current: 0.0.0) | pip install -U g4f
Using OpenaiChat provider and auto model
Traceback (most recent call last):
  File "C:\Users\admin\Desktop\g4f\gpt4free\test.py", line 17, in <module>
    response = client.chat.completions.create(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\client\client.py", line 118, in create
    return response if stream else next(response)
                                   ^^^^^^^^^^^^^^
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\client\client.py", line 57, in iter_append_model_and_provider
    for chunk in response:
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\client\client.py", line 29, in iter_response
    for idx, chunk in enumerate(response):
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\providers\base_provider.py", line 223, in create_completion
    yield loop.run_until_complete(await_callback(gen.__anext__))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\providers\base_provider.py", line 52, in await_callback
    return await callback()
           ^^^^^^^^^^^^^^^^
  File "C:\Users\admin\Desktop\g4f\gpt4free\g4f\Provider\needs_auth\OpenaiChat.py", line 422, in create_async_generator
    raise MissingAuthError("No arkose token found in .har file")
g4f.errors.MissingAuthError: No arkose token found in .har file

(venv) C:\Users\admin\Desktop\g4f\gpt4free>

Sometimes I may get a response in the logs as shown above.

here is the code I am using:

from g4f.client import Client
from g4f.Provider import OpenaiChat
from g4f.cookies import set_cookies_dir, read_cookie_files
import g4f.debug
import os

g4f.debug.logging = True

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

client = Client(
    provider=OpenaiChat,
    cookies=set_cookies_dir(cookies_dir),
)

response = client.chat.completions.create(
    model="auto",
    messages=[{"role": "user", "content": "Hello"}],
)

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