xtekky / gpt4free

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

[OpenaiChat] 0.2.1.9: RuntimeError: Response 401: {"detail":"Could not parse your authentication token. Please try signing in again."} #1619

Closed iG8R closed 4 months ago

iG8R commented 4 months ago
(venv) c:\gpt4free>g4f api --debug DEBUG --ignored-providers AItianhu AItianhuSpace Acytoo AiAsk AiChatOnline AiChatting AiService Aibn Aichat Ails Aivvm AsyncGeneratorProvider AsyncProvider Aura Bard BaseProvider Berlin Bestim Bing ChatAiGpt ChatAnywhere ChatBase ChatForAi Chatgpt4Online ChatgptAi ChatgptDemo ChatgptDemoAi ChatgptDuo ChatgptFree ChatgptLogin ChatgptNext ChatgptX Chatxyz CodeLinkAva CreateImagesProvider Cromicle DeepInfra DfeHub EasyChat Equing FakeGpt FastGpt Forefront FreeChatgpt FreeGpt GPTalk GeekGpt Gemini GeminiProCCFgptCN GeminiProChat GeminiProFreeChatGPT GeminiProGBeCo GeminiProTop GetGpt Gpt6 GptChatly GptForLove GptGo GptGod GptTalkRu H2o Hashnode HuggingChat Koala Komo Liaobots Llama2 Lockchat MikuChat MyShell Myshell OnlineGpt Opchatgpts OpenAssistant PerplexityAi PerplexityLabs Phind Pi Poe Raycast RetryProvider TalkAi Theb ThebApi V50 Vercel Vitalentum Wewordle Wuguokai Ylokh You Yqcloud
INFO:     Started server process [14760]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:1337 (Press CTRL+C to quit)
Using RetryProvider provider and gpt-3.5-turbo model
Using OpenaiChat provider
Error reading cookies from chrome for chat.openai.com: [Errno 13] Permission denied: 'C:\\Users\\iG8R\\AppData\\Roaming\\..\\Local\\Google\\Chrome\\User Data\\Default\\Network\\Cookies'
Read cookies from firefox for chat.openai.com
ClientResponseError: 401, message='Unauthorized', url=URL('https://chat.openai.com/backend-api/models')
Open browser with config dir: C:\Users\iG8R\AppData\Local\g4f\g4f
SUCCESS: The process "undetected_chromedriver.exe" with PID 15396 has been terminated.
INFO:     127.0.0.1:56223 - "POST /v1/chat/completions HTTP/1.1" 200 OK
Using RetryProvider provider and gpt-3.5-turbo model
Using OpenaiChat provider
OpenaiChat: RuntimeError: Response 401: {"detail":"Could not parse your authentication token. Please try signing in again."}
ERROR:root:RetryProvider failed:
OpenaiChat: RuntimeError: Response 401: {"detail":"Could not parse your authentication token. Please try signing in again."}
Traceback (most recent call last):
  File "c:\gpt4free\venv\Lib\site-packages\g4f\api\__init__.py", line 90, in chat_completions
    response = self.client.chat.completions.create(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\client.py", line 147, in create
    return response if stream else next(response)
                                   ^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\client.py", line 82, in iter_append_model_and_provider
    for chunk in response:
  File "c:\gpt4free\venv\Lib\site-packages\g4f\client.py", line 47, in iter_response
    for idx, chunk in enumerate(response):
  File "c:\gpt4free\venv\Lib\site-packages\g4f\providers\retry_provider.py", line 66, in create_completion
    self.raise_exceptions()
  File "c:\gpt4free\venv\Lib\site-packages\g4f\providers\retry_provider.py", line 115, in raise_exceptions
    raise RetryProviderError("RetryProvider failed:\n" + "\n".join([
g4f.errors.RetryProviderError: RetryProvider failed:
OpenaiChat: RuntimeError: Response 401: {"detail":"Could not parse your authentication token. Please try signing in again."}
INFO:     127.0.0.1:56265 - "POST /v1/chat/completions HTTP/1.1" 500 Internal Server Error
hlohaus commented 4 months ago

Maybe you use a new access_token or change the api_key to a access_token from OpenAI Chat. If i have a wrong access_token, i become a special error_message. g4f.errors.MissingAuthError: Missing or invalid "access_token". Add a new "api_key" please

iG8R commented 4 months ago

No, I didn't change anything neither use a new access_token nor change the api_key. image

hlohaus commented 4 months ago

I added a cookies is None check

iG8R commented 4 months ago

Still the same issue in version 0.2.2.0 - first request goes through fine (when the Chrome window flashes and authorization occurs), after that the error appears on every following request.

(venv) c:\gpt4free>g4f api --debug DEBUG --ignored-providers AItianhu AItianhuSpace Acytoo AiAsk AiChatOnline AiChatting AiService Aibn Aichat Ails Aivvm AsyncGeneratorProvider AsyncProvider Aura Bard BaseProvider Berlin Bestim Bing ChatAiGpt ChatAnywhere ChatBase ChatForAi Chatgpt4Online ChatgptAi ChatgptDemo ChatgptDemoAi ChatgptDuo ChatgptFree ChatgptLogin ChatgptNext ChatgptX Chatxyz CodeLinkAva CreateImagesProvider Cromicle DeepInfra DfeHub EasyChat Equing FakeGpt FastGpt Forefront FreeChatgpt FreeGpt GPTalk GeekGpt Gemini GeminiProCCFgptCN GeminiProChat GeminiProFreeChatGPT GeminiProGBeCo GeminiProTop GetGpt Gpt6 GptChatly GptForLove GptGo GptGod GptTalkRu H2o Hashnode HuggingChat Koala Komo Liaobots Llama2 Lockchat MikuChat MyShell Myshell OnlineGpt Opchatgpts OpenAssistant PerplexityAi PerplexityLabs Phind Pi Poe Raycast RetryProvider TalkAi Theb ThebApi V50 Vercel Vitalentum Wewordle Wuguokai Ylokh You Yqcloud
INFO:     Started server process [22992]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:1337 (Press CTRL+C to quit)
Using OpenaiChat provider and gpt-3.5-turbo model
Error reading cookies from chrome for chat.openai.com: [Errno 13] Permission denied: 'C:\\Users\\iG8R\\AppData\\Roaming\\..\\Local\\Google\\Chrome\\User Data\\Default\\Network\\Cookies'
Read cookies from firefox for chat.openai.com
ClientResponseError: 401, message='Unauthorized', url=URL('https://chat.openai.com/backend-api/models')
Open browser with config dir: C:\Users\iG8R\AppData\Local\g4f\g4f
INFO:     127.0.0.1:60329 - "POST /v1/chat/completions?provider=OpenaiChat HTTP/1.1" 200 OK
Using OpenaiChat provider and gpt-3.5-turbo model
ERROR:root:Response 401: {"detail":"Could not parse your authentication token. Please try signing in again."}
Traceback (most recent call last):
  File "c:\gpt4free\venv\Lib\site-packages\g4f\api\__init__.py", line 89, in chat_completions
    response = self.client.chat.completions.create(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\client.py", line 147, in create
    return response if stream else next(response)
                                   ^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\client.py", line 82, in iter_append_model_and_provider
    for chunk in response:
  File "c:\gpt4free\venv\Lib\site-packages\g4f\client.py", line 47, in iter_response
    for idx, chunk in enumerate(response):
  File "c:\gpt4free\venv\Lib\site-packages\g4f\providers\base_provider.py", line 204, in create_completion
    yield loop.run_until_complete(await_callback(gen.__anext__))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\nest_asyncio.py", line 99, in run_until_complete
    return f.result()
           ^^^^^^^^^^
  File "C:\Python312\Lib\asyncio\futures.py", line 203, in result
    raise self._exception.with_traceback(self._exception_tb)
  File "C:\Python312\Lib\asyncio\tasks.py", line 304, in __step_run_and_handle_result
    result = coro.send(None)
             ^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\providers\base_provider.py", line 200, in await_callback
    return await callback()
           ^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\Provider\needs_auth\OpenaiChat.py", line 410, in create_async_generator
    raise RuntimeError(f"Response {response.status}: {await response.text()}")
RuntimeError: Response 401: {"detail":"Could not parse your authentication token. Please try signing in again."}
INFO:     127.0.0.1:60366 - "POST /v1/chat/completions?provider=OpenaiChat HTTP/1.1" 500 Internal Server Error
Using OpenaiChat provider and gpt-3.5-turbo model
ERROR:root:Response 401: {"detail":"Could not parse your authentication token. Please try signing in again."}
Traceback (most recent call last):
  File "c:\gpt4free\venv\Lib\site-packages\g4f\api\__init__.py", line 89, in chat_completions
    response = self.client.chat.completions.create(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\client.py", line 147, in create
    return response if stream else next(response)
                                   ^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\client.py", line 82, in iter_append_model_and_provider
    for chunk in response:
  File "c:\gpt4free\venv\Lib\site-packages\g4f\client.py", line 47, in iter_response
    for idx, chunk in enumerate(response):
  File "c:\gpt4free\venv\Lib\site-packages\g4f\providers\base_provider.py", line 204, in create_completion
    yield loop.run_until_complete(await_callback(gen.__anext__))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\nest_asyncio.py", line 99, in run_until_complete
    return f.result()
           ^^^^^^^^^^
  File "C:\Python312\Lib\asyncio\futures.py", line 203, in result
    raise self._exception.with_traceback(self._exception_tb)
  File "C:\Python312\Lib\asyncio\tasks.py", line 304, in __step_run_and_handle_result
    result = coro.send(None)
             ^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\providers\base_provider.py", line 200, in await_callback
    return await callback()
           ^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\Provider\needs_auth\OpenaiChat.py", line 410, in create_async_generator
    raise RuntimeError(f"Response {response.status}: {await response.text()}")
RuntimeError: Response 401: {"detail":"Could not parse your authentication token. Please try signing in again."}
INFO:     127.0.0.1:60398 - "POST /v1/chat/completions?provider=OpenaiChat HTTP/1.1" 500 Internal Server Error
iG8R commented 4 months ago

One remark - all this only happens with the g4f API, the g4f GUI works fine.

iG8R commented 4 months ago

Only with this OpenaiChat.py file from version 0.2.1.8 both g4f API and g4f WebGUI work fine. OpenaiChat.md5 0a806927d7781ef8c1f4444ed44e0a17 *OpenaiChat.py

image

hlohaus commented 4 months ago

I improved the cookie and api_key usage in OpenaiChat Now it use 1. api_key as argument or 2. cookies or 3. the browser #1637

iG8R commented 4 months ago

Still the same error:( And still in g4f WebGUI works fine, but in g4f API - the following error occurs after the first successful response. Is there any way to add more debugging information to the code to find out why this is happening?

(venv) c:\gpt4free>g4f api --debug DEBUG --ignored-providers AItianhu AItianhuSpace Acytoo AiAsk AiChatOnline AiChatting AiService Aibn Aichat Ails Aivvm AsyncGeneratorProvider AsyncProvider Aura Bard BaseProvider Berlin Bestim Bing ChatAiGpt ChatAnywhere ChatBase ChatForAi Chatgpt4Online ChatgptAi ChatgptDemo ChatgptDemoAi ChatgptDuo ChatgptFree ChatgptLogin ChatgptNext ChatgptX Chatxyz CodeLinkAva CreateImagesProvider Cromicle DeepInfra DfeHub EasyChat Equing FakeGpt FastGpt Forefront FreeChatgpt FreeGpt GPTalk GeekGpt Gemini GeminiProCCFgptCN GeminiProChat GeminiProFreeChatGPT GeminiProGBeCo GeminiProTop GetGpt Gpt6 GptChatly GptForLove GptGo GptGod GptTalkRu H2o Hashnode HuggingChat Koala Komo Liaobots Llama2 Lockchat MikuChat MyShell Myshell OnlineGpt Opchatgpts OpenAssistant PerplexityAi PerplexityLabs Phind Pi Poe Raycast RetryProvider TalkAi Theb ThebApi V50 Vercel Vitalentum Wewordle Wuguokai Ylokh You Yqcloud
INFO:     Started server process [19732]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:1337 (Press CTRL+C to quit)
Using OpenaiChat provider and gpt-3.5-turbo model
ClientResponseError: 401, message='Unauthorized', url=URL('https://chat.openai.com/backend-api/models')
Open browser with config dir: C:\Users\iG0R\AppData\Local\g4f\g4f
INFO:     127.0.0.1:60048 - "POST /v1/chat/completions?provider=OpenaiChat HTTP/1.1" 200 OK
Using OpenaiChat provider and gpt-3.5-turbo model
ERROR:root:Response 401: {"detail":"Could not parse your authentication token. Please try signing in again."}
Traceback (most recent call last):
  File "c:\gpt4free\venv\Lib\site-packages\g4f\api\__init__.py", line 89, in chat_completions
    response = self.client.chat.completions.create(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\client.py", line 147, in create
    return response if stream else next(response)
                                   ^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\client.py", line 82, in iter_append_model_and_provider
    for chunk in response:
  File "c:\gpt4free\venv\Lib\site-packages\g4f\client.py", line 47, in iter_response
    for idx, chunk in enumerate(response):
  File "c:\gpt4free\venv\Lib\site-packages\g4f\providers\base_provider.py", line 204, in create_completion
    yield loop.run_until_complete(await_callback(gen.__anext__))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\nest_asyncio.py", line 99, in run_until_complete
    return f.result()
           ^^^^^^^^^^
  File "C:\Python312\Lib\asyncio\futures.py", line 203, in result
    raise self._exception.with_traceback(self._exception_tb)
  File "C:\Python312\Lib\asyncio\tasks.py", line 304, in __step_run_and_handle_result
    result = coro.send(None)
             ^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\providers\base_provider.py", line 200, in await_callback
    return await callback()
           ^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\Provider\needs_auth\OpenaiChat.py", line 412, in create_async_generator
    raise RuntimeError(f"Response {response.status}: {await response.text()}")
RuntimeError: Response 401: {"detail":"Could not parse your authentication token. Please try signing in again."}
INFO:     127.0.0.1:60075 - "POST /v1/chat/completions?provider=OpenaiChat HTTP/1.1" 500 Internal Server Error
hlohaus commented 4 months ago

Can you remove your api_key from API Integration? It overrides the value from the G4F browser.

iG8R commented 4 months ago

I didn't add any api_key for OpenaiChat.

iG8R commented 4 months ago

g4f-OpenaiChat-1619-issue-Video_2024-02-27_20-18-48.webm

hlohaus commented 4 months ago

There is one * in your mask. Please remove them.

iG8R commented 4 months ago

Sorry, could you please point out where I need to remove the mask (line number)?

I upgraded to version 0.2.2.5 and now even the g4f GUI has stopped working...

Using OpenaiChat provider and gpt-4 model
Read cookies from chrome for chat.openai.com
Read cookies from firefox for chat.openai.com
ERROR:root:Response 401: {"detail":"Could not parse your authentication token. Please try signing in again."}
Traceback (most recent call last):
  File "c:\gpt4free\venv\Lib\site-packages\g4f\gui\server\backend.py", line 191, in _create_response_stream
    for chunk in ChatCompletion.create(**kwargs):
  File "c:\gpt4free\venv\Lib\site-packages\g4f\providers\base_provider.py", line 204, in create_completion
    yield loop.run_until_complete(await_callback(gen.__anext__))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\asyncio\base_events.py", line 664, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\providers\base_provider.py", line 200, in await_callback
    return await callback()
           ^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\Provider\needs_auth\OpenaiChat.py", line 426, in create_async_generator
    raise RuntimeError(f"Response {response.status}: {await response.text()}")
RuntimeError: Response 401: {"detail":"Could not parse your authentication token. Please try signing in again."}
127.0.0.1 - - [28/Feb/2024 13:36:50] "POST /backend-api/v2/conversation HTTP/1.1" 200 -
INFO:werkzeug:127.0.0.1 - - [28/Feb/2024 13:36:50] "POST /backend-api/v2/conversation HTTP/1.1" 200 -

And the g4f API doesn't even process the first request like it did in 0.2.2.3:

(venv) c:\gpt4free>g4f api --debug DEBUG --ignored-providers AItianhu AItianhuSpace Acytoo AiAsk AiChatOnline AiChatting AiService Aibn Aichat Ails Aivvm AsyncGeneratorProvider AsyncProvider Aura Bard BaseProvider Berlin Bestim Bing ChatAiGpt ChatAnywhere ChatBase ChatForAi Chatgpt4Online ChatgptAi ChatgptDemo ChatgptDemoAi ChatgptDuo ChatgptFree ChatgptLogin ChatgptNext ChatgptX Chatxyz CodeLinkAva CreateImagesProvider Cromicle DeepInfra DfeHub EasyChat Equing FakeGpt FastGpt Forefront FreeChatgpt FreeGpt GPTalk GeekGpt Gemini GeminiProCCFgptCN GeminiProChat GeminiProFreeChatGPT GeminiProGBeCo GeminiProTop GetGpt Gpt6 GptChatly GptForLove GptGo GptGod GptTalkRu H2o Hashnode HuggingChat Koala Komo Liaobots Llama2 Lockchat MikuChat MyShell Myshell OnlineGpt Opchatgpts OpenAssistant PerplexityAi PerplexityLabs Phind Pi Poe Raycast RetryProvider TalkAi Theb ThebApi V50 Vercel Vitalentum Wewordle Wuguokai Ylokh You Yqcloud
INFO:     Started server process [27544]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:1337 (Press CTRL+C to quit)
Using OpenaiChat provider and gpt-3.5-turbo model
ERROR:root:Response 401: {"detail":"Could not parse your authentication token. Please try signing in again."}
Traceback (most recent call last):
  File "c:\gpt4free\venv\Lib\site-packages\g4f\api\__init__.py", line 89, in chat_completions
    response = self.client.chat.completions.create(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\client.py", line 155, in create
    return response if stream else next(response)
                                   ^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\client.py", line 82, in iter_append_model_and_provider
    for chunk in response:
  File "c:\gpt4free\venv\Lib\site-packages\g4f\client.py", line 47, in iter_response
    for idx, chunk in enumerate(response):
  File "c:\gpt4free\venv\Lib\site-packages\g4f\providers\base_provider.py", line 204, in create_completion
    yield loop.run_until_complete(await_callback(gen.__anext__))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\nest_asyncio.py", line 99, in run_until_complete
    return f.result()
           ^^^^^^^^^^
  File "C:\Python312\Lib\asyncio\futures.py", line 203, in result
    raise self._exception.with_traceback(self._exception_tb)
  File "C:\Python312\Lib\asyncio\tasks.py", line 304, in __step_run_and_handle_result
    result = coro.send(None)
             ^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\providers\base_provider.py", line 200, in await_callback
    return await callback()
           ^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\Provider\needs_auth\OpenaiChat.py", line 426, in create_async_generator
    raise RuntimeError(f"Response {response.status}: {await response.text()}")
RuntimeError: Response 401: {"detail":"Could not parse your authentication token. Please try signing in again."}
hlohaus commented 4 months ago

Screenshot_2024-02-28-16-49-48-893_com.android.chrome.jpg

I created a screenshot from that. The password field is not empty. You need to enter the right access_token or keep it blank.

iG8R commented 4 months ago

I've tried it before already, but to no avail.

PS. Some clients do not allow to leave the API field blank, so I am forced to enter any character, in my case I enter a space character as a rule. Is it possible in the future to make g4f interpret a space as an empty field?

g4f-OpenaiChat-1619-02-2024-02-28_19-09-52.webm

hlohaus commented 4 months ago

If you send spaces, the API key will be "Bearer". I will add a ignore case for it.

iG8R commented 4 months ago

Hurray! It works! Thank you so much!

chekamarue commented 4 months ago

is there a tutorial or an easy step by step on how to make chat.openai.com work properly ! it said pass cookies! set_cookies("chat.openai.com",{"CF_CLEARANCE":**, "SESSION_TOKEN":**} but it still not working for me

iG8R commented 4 months ago

@chekamarue Take a look here https://github.com/xtekky/gpt4free/issues/1539 and here https://github.com/xtekky/gpt4free?tab=readme-ov-file#configuration

chekamarue commented 4 months ago

@chekamarue Take a look here #1539 and here https://github.com/xtekky/gpt4free?tab=readme-ov-file#configuration

Thank you

iG8R commented 4 months ago

@hlohaus

This is some kind of fantastic... Out of the blue, OpenaiChat stopped working again. And now even in the WebGUI. Moreover, it's evident that when using file version 0.2.2.6, there's absolutely no interaction with Chrome (it could be seen by changes in c:\Users\iG8R\AppData\Local\g4f\g4f\) But version 0.2.1.8 still feels itself good.

g4f-OpenaiChat-1619-03-Video_2024-03-02_03-43-45.webm

hlohaus commented 4 months ago

Do you have a error message? Maybe OpenAI did some changes.

iG8R commented 4 months ago

Before this happened there was an error 429 - something there about the fact that I used more requests than allowed in 1 hour, so I need to wait for that hour to expire. And then it all began. I completely cleared the directory c:\Users\iG8R\AppData\Local\g4f\ and restarted g4f, but it kept giving the same error ERROR: root :Response 401: {"detail": "Could not parse your authentication token. Please try signing in again."} Then I replaced OpenaiChat.py with version 0.2.1.8, but for some time it gave the following error selenium.common.exceptions.WebDriverException: Message: disconnected: not connected to DevTools. And after some time, OpenaiChat.py 0.2.1.8 started working, whereas 0.2.2.6 - not at all.

iG8R commented 4 months ago

Maybe OpenAI did some changes.

If there had been a problem from the OpenAI side, there would have been no issues with requests to Chrome from the OpenaiChat.py version 0.2.2.6, while version 0.2.1.8 works perfectly fine.

iG8R commented 4 months ago

Hmmm... I just checked again and... oh, miracle - OpenaiChat.py version 0.2.2.6 is working again. Noticed one peculiarity - with the first request to g4f after starting the server

image

iG8R commented 4 months ago

Self-asked, self-answered. It turns out that in version 0.2.2.6, a mechanism for searching cookies of all browsers installed on the system has been implemented, and requests to g4f's own Chrome have completely disappeared. I don't know, on one hand, it's very convenient that if one logs in from the standard browser, they don't need to do any other actions, but on the other hand, it's confusing because such a mechanism was not used before. Maybe it's worth playing it safe, just in case there are problems with accessing cookies of browsers installed on the system, then address g4f's own? Instead of how it is now, if there are any issues with cookies from standard browsers, OpenaiChat stops working altogether and gives such confusing errors.

iG8R commented 4 months ago

Right now version 0.2.2.6 again has ceased to work properly. I manually logged into https://chat.openai.com with Firefox - still got the same error, then with Edge - nothing changed, and only after I logged in with my system's Chrome, OpenaiChat started work fine without any authentication token errors. And, according to ProcessMonitor, during this whole process, there were absolutely no attempts to get in touch with the Chrome config dir in c:\Users\iG8R\AppData\Local\g4f\g4f.

hlohaus commented 4 months ago

It first try to read it from g4f browser. But if it doesn't find cookies, it try chrome, firefox and so on. That was so in every version. New is only the reading of the access token from the auth header.

iG8R commented 4 months ago

It turns out that this is not entirely true, because in the screencast from the post https://github.com/xtekky/gpt4free/issues/1619#issuecomment-1974205185 it is clearly seen that version 0.2.2.6 does not interact with the g4f browser's configuration directory at all, while version 0.2.1.8 does exactly that.

Is there any other mechanism besides looking at ProcessMonitor logs to track what exactly version 0.2.2.6 is doing during all of this process step-by-step?

chekamarue commented 4 months ago

It turns out that this is not entirely true, because in the screencast from the post #1619 (comment) it is clearly seen that version 0.2.2.6 does not interact with the g4f browser's configuration directory at all, while version 0.2.1.8 does exactly that.

Is there any other mechanism besides looking at ProcessMonitor logs to track what exactly version 0.2.2.6 is doing during all of this process step-by-step?

Just manually put the auth access and update to the last version, that it. reading cookies on some machines is restricted due to security issues.

iG8R commented 4 months ago

@chekamarue

If there were problems with reading cookies on my system, then version 0.2.1.8 would not work either. There is clearly a problem with the conditional operator here, when in version 0.2.1.8, if there is a problem with reading cookies from the system's browsers, it goes to reading cookies from the g4f browser, while in version 0.2.2.6 - this conditional operator does not work correctly and without going to the g4f config dir, it terminates the script with an error, since it really does not find the necessary tokens anywhere.

hlohaus commented 4 months ago

Okay, is there still a issue? What are the issue? What exactly are doing? Do you pass a access_token? Why you aren't pass a access_token? Do it not working on first or on the second time?

iG8R commented 4 months ago

Okay, is there still a issue?

From the time this https://github.com/xtekky/gpt4free/issues/1619#issuecomment-1974950429 comment was written until now, continues to work.

What are the issue?

The problem is that, starting from version 0.2.1.9, it either immediately gives an authorization error, or from version 0.2.2.6, the authorization suddenly crashes out of the blue, while there were no such problems at all before till version 0.2.1.8.

What exactly are doing?

I run g4f gui or g4f api. When working with both WebGUI and API in versions starting from 0.2.1.9, an error is encountered: [RuntimeError: Response 401: {"detail":"Could not parse your authentication token. Please try signing in again."}](https://github.com/xtekky/gpt4free/issues/1619#top)

Do you pass a access_token?

How can I pass the access_token in the WebGUI? I just enter in the WebGUI and start the conversation, you can see it in the screencast of the comment https://github.com/xtekky/gpt4free/issues/1619#issuecomment-1974205185

Why you aren't pass a access_token?

How can I pass an access_token in the WebGUI?

Do it not working on first or on the second time?

In versions from 0.2.1.9 to 0.2.2.5, it didn't work at all due to an authentication error, in the fixed version 0.2.2.6, it works periodically.

iG8R commented 4 months ago

Next time, if this issue still occurs, I'll debug it with pdb.

iG8R commented 4 months ago

After slightly more than a day had passed, the same problem arose again. Finally, I figured out why this is happening. Everything is visible in the screencast. In fact, OpenaiChat.py reads cookies from system browsers without any issues; however, for some reason, if these cookies are not entirely fresh, https://chat.openai.com interprets the tokens contained in them as invalid. And only when manually authorizing, OpenaiChat.py starts functioning normally. Is it possible to implement a mechanism so that when an error 401 occurs, g4f refers to its own browser instead of the system one, in which authorization on https://chat.openai.com occurs automatically, thus ensuring that the cookies are always fresh?

g4f-OpenaiChat-1619-04-Video_2024-03-05_00-51-44.webm

hlohaus commented 4 months ago

The access_token cookie expires already after 4 hours. Did you run the API for a day. But the static cache doesn't expires. I could expire them after 4 hours too.

iG8R commented 4 months ago

Yes, on my home LAN server usually g4f (GUI and API) runs continuously until some error occurs, thus I need to restart it. And after this restart, in the case of system browsers (versions 0.2.1.9 and above) I get the above error and, as it turned out, need to manually relogin into https://chat.openai.com, while in the case of g4f browser (versions 0.2.1.8 and earlier), everything goes automatically.