Code Monkey home page Code Monkey logo

Comments (31)

hlohaus avatar hlohaus commented on June 14, 2024

Is the .har file in /mnt/docs?

from gpt4free.

plia7 avatar plia7 commented on June 14, 2024

Is the .har file in /mnt/docs?

Yes, it's the same place I always placed it and it worked before. I'm also obtaining the HAR file exactly like I used to before so not sure why it doesn't work anymore?

from gpt4free.

plia7 avatar plia7 commented on June 14, 2024

Is the .har file in /mnt/docs?

Are you able to reproduce the issue on your end? Is there an alternative way to supply it with the login credentials without the HAR file such as email and password or some session key?

Thanks.

from gpt4free.

hlohaus avatar hlohaus commented on June 14, 2024

.har files are needed for plus accounts. Others work with NoDriver too.
To install NoDriver, use: pip install nodriver.

The .har file must be in the current directory and must end with .har.

from gpt4free.

plia7 avatar plia7 commented on June 14, 2024

.har files are needed for plus accounts. Others work with NoDriver too.
To install NoDriver, use: pip install nodriver.

The .har file must be in the current directory and must end with .har.

I'm using ChatGPT v3.5 (I don't think it's ChatGPT v4 which is a plus account). So do I still need the .har file? If not, what do I need to supply it with alternatively?

Yes, it's placed same place as before and it stopped working:

me:/mnt/docs# ls
chat.openai.com.har   
chatgpt.py            
me:/mnt/docs# python3 ./chatgpt.py

You: chatgpt are you here 
New g4f version: 0.3.0.7 (current: 0.3.0.6) | pip install -U g4f

GPT: Traceback (most recent call last):
  File "/root/mnt/docs/./chatgpt.py", line 63, in <module>
    for chunk in stream:
  File "/usr/lib/python3.9/site-packages/g4f/providers/base_provider.py", line 216, in create_completion
    yield loop.run_until_complete(await_callback(gen.__anext__))
  File "/usr/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/usr/lib/python3.9/site-packages/g4f/providers/base_provider.py", line 45, in await_callback
    return await callback()
  File "/usr/lib/python3.9/site-packages/g4f/Provider/needs_auth/OpenaiChat.py", line 383, in create_async_generator
    cls.default_model = cls.get_model(await cls.get_default_model(session, cls._headers))
  File "/usr/lib/python3.9/site-packages/g4f/Provider/needs_auth/OpenaiChat.py", line 184, in get_default_model
    raise MissingAuthError('Add a "api_key" or a .har file' if cls._api_key is None else "Invalid api key")
g4f.errors.MissingAuthError: Add a "api_key" or a .har file

Does it work for you?

Thanks.

from gpt4free.

plia7 avatar plia7 commented on June 14, 2024

.har files are needed for plus accounts. Others work with NoDriver too.
To install NoDriver, use: pip install nodriver.

The .har file must be in the current directory and must end with .har.

I'm using ChatGPT v3.5 (I don't think it's ChatGPT v4 which is a plus account). So do I still need the .har file? If not, what do I need to supply it with alternatively?

Yes, it's placed same place as before and it stopped working:

me:/mnt/docs# ls
chat.openai.com.har   
chatgpt.py            
me:/mnt/docs# python3 ./chatgpt.py

You: chatgpt are you here 
New g4f version: 0.3.0.7 (current: 0.3.0.6) | pip install -U g4f

GPT: Traceback (most recent call last):
  File "/root/mnt/docs/./chatgpt.py", line 63, in <module>
    for chunk in stream:
  File "/usr/lib/python3.9/site-packages/g4f/providers/base_provider.py", line 216, in create_completion
    yield loop.run_until_complete(await_callback(gen.__anext__))
  File "/usr/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/usr/lib/python3.9/site-packages/g4f/providers/base_provider.py", line 45, in await_callback
    return await callback()
  File "/usr/lib/python3.9/site-packages/g4f/Provider/needs_auth/OpenaiChat.py", line 383, in create_async_generator
    cls.default_model = cls.get_model(await cls.get_default_model(session, cls._headers))
  File "/usr/lib/python3.9/site-packages/g4f/Provider/needs_auth/OpenaiChat.py", line 184, in get_default_model
    raise MissingAuthError('Add a "api_key" or a .har file' if cls._api_key is None else "Invalid api key")
g4f.errors.MissingAuthError: Add a "api_key" or a .har file

Does it work for you?

Thanks.

@hlohaus Any updates on this?

Thanks.

from gpt4free.

hlohaus avatar hlohaus commented on June 14, 2024

Are your .har files created correctly? The .har file solution works for me and other users.

from gpt4free.

plia7 avatar plia7 commented on June 14, 2024

Are your .har files created correctly? The .har file solution works for me and other users.

To create the HAR file, I follow these instructions:

Generating a .HAR File
To utilize the OpenaiChat provider, a .har file is required from https://chat.openai.com/. Follow the steps below to create a valid .har file:

Navigate to https://chat.openai.com/ using your preferred web browser and log in with your credentials.

Access the Developer Tools in your browser. This can typically be done by right-clicking the page and selecting "Inspect," or by pressing F12 or Ctrl+Shift+I (Cmd+Option+I on a Mac).

With the Developer Tools open, switch to the "Network" tab.

Reload the website to capture the loading process within the Network tab.

Initiate an action in the chat which can be capture in the .har file.

Right-click any of the network activities listed and select "Save all as HAR with content" to export the .har file.

It generates a file I save as "chatgpt.har" and copy it to mnt/docs folder where chatgpt.py is located.

It worked before, but it stopped working so I'm not doing anything different than what I did before.

Is there a tool or script to fetch the .har from chrome browser automatically to make sure I'm not doing anything wrong when fetching it manually following these instructions?

I also just updated the g4f package but I still get the same message:

Successfully installed g4f-0.3.0.8
me:/mnt/docs# ls
chatgpt.har           
chatgpt.py            
me:/mnt/docs# chatgpt

You: how are you?

GPT: Traceback (most recent call last):
  File "/root/mnt/docs/chatgpt.py", line 63, in <module>
    for chunk in stream:
  File "/usr/lib/python3.9/site-packages/g4f/providers/base_provider.py", line 216, in create_completion
    yield loop.run_until_complete(await_callback(gen.__anext__))
  File "/usr/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/usr/lib/python3.9/site-packages/g4f/providers/base_provider.py", line 45, in await_callback
    return await callback()
  File "/usr/lib/python3.9/site-packages/g4f/Provider/needs_auth/OpenaiChat.py", line 409, in create_async_generator
    cls.default_model = cls.get_model(await cls.get_default_model(session, cls._headers))
  File "/usr/lib/python3.9/site-packages/g4f/Provider/needs_auth/OpenaiChat.py", line 200, in get_default_model
    raise MissingAuthError('Add a "api_key" or a .har file' if cls._api_key is None else "Invalid api key")
g4f.errors.MissingAuthError: Add a "api_key" or a .har file

Any alternative way to specify the auth for ChatGPT 3.5 provider (free account) without using the .HAR file? Do you have Discord to discuss? Does it matter what's the full name of the file or as long as it's *.har it should be ok? Is there any way to inspect the .har or debug this case to see why it can't find or fetch the .har file?

Thanks.

from gpt4free.

plia7 avatar plia7 commented on June 14, 2024

@hlohaus I just tried a second windows pc with python, I'm encountering the same issue.
So I have this in both Linux x86 machine and windows x64 machine both with python installed.

I downloaded the .har multiple times, trying to write multiple times to chatgpt before saving the .har file, but I still keep getting the same error message.

It can't be that I'm the only one that's reporting this issue?
This doesn't make any sense. Please fix this bug. Let me know what troubleshoot or debug information do you need, I can also share my screen on discord to show you the problem.

Thanks.

from gpt4free.

iG8R avatar iG8R commented on June 14, 2024

@plia7
What directory did you save the har file in?

PS. I had the same problem, but version 0.3.0.7 solved it.
#1795 (comment)

from gpt4free.

plia7 avatar plia7 commented on June 14, 2024

@plia7 What directory did you save the har file in?

PS. I had the same problem, but version 0.3.0.7 solved it. #1795 (comment)

I put it in both the root folder where chatgpt.py is located as well as inside /mnt/docs.
Again, I'm not doing anything different than I did before when it worked, but it just stopped working for me.
I also upgraded to the latest version 0.3.0.8 in both environments but it still doesn't work.

Do you have some basic code snippet that I can try that works for you to make sure my chatgpt.py script is not causing the issue?

Do you have a Discord channel or user I can show you the problem?

@hlohaus @iG8R Is there any guaranteed folder where I can put the .har file like python site packages or something or is there a way I can force it to read the file from a specific location?

@iG8R Your issue doesn't sound the same as mine as yours doesn't say that "har file is missing?" so I think you had a different issue than mine?

Thanks.

from gpt4free.

iG8R avatar iG8R commented on June 14, 2024

@plia7
Yes, my issue was a little different.
In your case, when it says "har file is missing", IMHO, it means it can't find the har file in the g4f specific directory where it should be.

I do not have Linux, but I suggest you try the following on Windows, which works fine for me:

  1. Clone the g4f repository, e.g.
    c:\g4f\
  2. Create a virtual environment:
    Enter c:\g4f\ and run from command line python -m venv venv
  3. Activate the virtual environment:
    Still when you are inside c:\g4f\ run from command line .\venv\Scripts\activate
  4. Still inside c:\g4f\ run from command line pip install . (Don't forget to put a period at the end)
  5. If needed also install:
    pip install uvicorn and pip install fastapi
  6. First, run g4f api --debug without any har file in the c:\g4f\har_and_cookies\ directory
  7. Then copy your har file to the c:\g4f\har_and_cookies\ directory and run g4f api --debug again. You will then be able to see comments on how g4f handles your har file.

image

from gpt4free.

iG8R avatar iG8R commented on June 14, 2024

Do you have some basic code snippet that I can try that works for you to make sure my chatgpt.py script is not causing the issue?

I don't use any code snippets, just API calls from other applications, e.g.

  1. https://github.com/pot-app/pot-desktop
    Request Path http://127.0.0.1:1337/v1/chat/completions?provider=OpenaiChat
    Api Key - whitespace

  1. https://github.com/immersive-translate/immersive-translate/

from gpt4free.

hlohaus avatar hlohaus commented on June 14, 2024

Hey, @plia7! How do you run your script? Do you just type python chatgpt.py or do you use an absolute or relative path like python .../my_dir/chatgpt.py? Try changing to your directory first with cd .../my_dir/ and see if that works.

from gpt4free.

plia7 avatar plia7 commented on June 14, 2024

Hey, @plia7! How do you run your script? Do you just type python chatgpt.py or do you use an absolute or relative path like python .../my_dir/chatgpt.py? Try changing to your directory first with cd .../my_dir/ and see if that works.

Yes, I change directory where chatgpt.py is located and then I run it by the command "python3 chatgpt.py" but that's failing.
Maybe you could add an option to specify the har in a parameter to make sure the package doesn't get confused like that?

Thanks.

from gpt4free.

plia7 avatar plia7 commented on June 14, 2024

Hey, @plia7! How do you run your script? Do you just type python chatgpt.py or do you use an absolute or relative path like python .../my_dir/chatgpt.py? Try changing to your directory first with cd .../my_dir/ and see if that works.

My friend was able to get this to work in his newly set environment after getting the same error about missing har file although he placed it. He updated to 0.3.1.0 and then it started to work. I tried to do the same but I still get the error. I made sure to remove any har file copies I had so it doesn't take the wrong one.

@hlohaus Could you explain please how it determines which HAR file to use? Is there a place I can put the file to ensure it will take priority over any other har file in the running path? I think this is not environment issue rather it's a code issue that should be fixed, because it's clearly failing to pick up on the har file as in my case.

Thanks.

from gpt4free.

hlohaus avatar hlohaus commented on June 14, 2024

Hey, why can't you just put the .har file in the current directory? It reads all the .har files, but then only uses the last one it finds that matches alphabetically.

from gpt4free.

plia7 avatar plia7 commented on June 14, 2024

Hey, why can't you just put the .har file in the current directory? It reads all the .har files, but then only uses the last one it finds that matches alphabetically.

I already placed it in the current directory. It doesn't work.

from gpt4free.

plia7 avatar plia7 commented on June 14, 2024

@iG8R Thanks for the detailed reply.
Could you explain please how do you make a REST POST call to this endpoint:

http://127.0.0.1:1337/v1/chat/completions?provider=OpenaiChat

What body do you use?

When I try to make a REST POST call to http://127.0.0.1:1337/v1/chat/completions?provider=OpenaiChat
without any body, this is the response I get back:

INFO: 127.0.0.1:64627 - "POST /v1/chat/completions?provider=OpenaiChat HTTP/1.1" 422 Unprocessable Entity

And this is the response body I get:

{
    "detail": [
        {
            "loc": [
                "body"
            ],
            "message": "Input should be a valid dictionary or object to extract fields from",
            "type": "model_attributes_type"
        }
    ]
}

Thanks.

from gpt4free.

iG8R avatar iG8R commented on June 14, 2024

@plia7
I don't use any code snippets, all the bodies are "provided" by the apps I use (see the attached screenshot).
Try to execute them and check from the console logs - is the har file being processed as it should or not?

image

from gpt4free.

plia7 avatar plia7 commented on June 14, 2024

@plia7

I don't use any code snippets, all the bodies are "provided" by the apps I use (see the attached screenshot).

Try to execute them and check from the console logs - is the har file being processed as it should or not?

image

Do I have to install both of these programs?

from gpt4free.

iG8R avatar iG8R commented on June 14, 2024

Do I have to install both of these programs?

Any will do.

from gpt4free.

plia7 avatar plia7 commented on June 14, 2024

Do I have to install both of these programs?

Any will do.

Ok so when I try to add the call in the pot program as in your screenshot, this is the message I get:

C:\Users\me\Documents>C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\Scripts\g4f.exe api --debug
Starting server... [g4f v-0.3.1.0] (debug)
INFO:     Will watch for changes in these directories: ['C:\\Users\\me\\Documents']
INFO:     Uvicorn running on http://0.0.0.0:1337 (Press CTRL+C to quit)
INFO:     Started reloader process [27076] using WatchFiles
INFO:     Started server process [5984]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
Using OpenaiChat provider and gpt-3.5-turbo model
INFO:     127.0.0.1:62560 - "POST /v1/chat/completions?provider=OpenaiChat HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
  + Exception Group Traceback (most recent call last):
  |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\_utils.py", line 87, in collapse_excgroups
  |     yield
  |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\middleware\base.py", line 190, in __call__
  |     async with anyio.create_task_group() as task_group:
  |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\anyio\_backends\_asyncio.py", line 678, in __aexit__
  |     raise BaseExceptionGroup(
  | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\uvicorn\protocols\http\httptools_impl.py", line 411, in run_asgi
    |     result = await app(  # type: ignore[func-returns-value]
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\uvicorn\middleware\proxy_headers.py", line 69, in __call__
    |     return await self.app(scope, receive, send)
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\fastapi\applications.py", line 1054, in __call__
    |     await super().__call__(scope, receive, send)
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\applications.py", line 123, in __call__
    |     await self.middleware_stack(scope, receive, send)
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\middleware\errors.py", line 186, in __call__
    |     raise exc
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\middleware\errors.py", line 164, in __call__
    |     await self.app(scope, receive, _send)
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\middleware\base.py", line 189, in __call__
    |     with collapse_excgroups():
    |   File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.752.0_x64__qbz5n2kfra8p0\Lib\contextlib.py", line 158, in __exit__
    |     self.gen.throw(value)
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\_utils.py", line 93, in collapse_excgroups
    |     raise exc
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\middleware\base.py", line 191, in __call__
    |     response = await self.dispatch_func(request, call_next)
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\g4f\api\__init__.py", line 84, in authorization
    |     return await call_next(request)
    |            ^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\middleware\base.py", line 165, in call_next
    |     raise app_exc
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\middleware\base.py", line 151, in coro
    |     await self.app(scope, receive_or_disconnect, send_no_error)
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\middleware\exceptions.py", line 65, in __call__
    |     await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\_exception_handler.py", line 64, in wrapped_app
    |     raise exc
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\_exception_handler.py", line 53, in wrapped_app
    |     await app(scope, receive, sender)
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\routing.py", line 756, in __call__
    |     await self.middleware_stack(scope, receive, send)
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\routing.py", line 776, in app
    |     await route.handle(scope, receive, send)
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\routing.py", line 297, in handle
    |     await self.app(scope, receive, send)
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\routing.py", line 77, in app
    |     await wrap_app_handling_exceptions(app, request)(scope, receive, send)
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\_exception_handler.py", line 64, in wrapped_app
    |     raise exc
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\_exception_handler.py", line 53, in wrapped_app
    |     await app(scope, receive, sender)
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\routing.py", line 72, in app
    |     response = await func(request)
    |                ^^^^^^^^^^^^^^^^^^^
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\fastapi\routing.py", line 278, in app
    |     raw_response = await run_endpoint_function(
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\fastapi\routing.py", line 191, in run_endpoint_function
    |     return await dependant.call(**values)
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\g4f\api\__init__.py", line 161, in chat_completions
    |     return JSONResponse((await response).to_json())
    |                          ^^^^^^^^^^^^^^
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\g4f\client\async_client.py", line 63, in iter_append_model_and_provider
    |     async for chunk in response:
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\g4f\client\async_client.py", line 37, in iter_response
    |     async for chunk in response:
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\g4f\Provider\needs_auth\OpenaiChat.py", line 419, in create_async_generator
    |     await raise_for_status(response)
    |   File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\g4f\requests\raise_for_status.py", line 28, in raise_for_status_async
    |     raise ResponseStatusError(f"Response {response.status}: {message}")
    | g4f.errors.ResponseStatusError: Response 401: {"detail":"Unauthorized"}
    +------------------------------------

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\uvicorn\protocols\http\httptools_impl.py", line 411, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\uvicorn\middleware\proxy_headers.py", line 69, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\fastapi\applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\middleware\errors.py", line 186, in __call__
    raise exc
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\middleware\errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\middleware\base.py", line 189, in __call__
    with collapse_excgroups():
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.752.0_x64__qbz5n2kfra8p0\Lib\contextlib.py", line 158, in __exit__
    self.gen.throw(value)
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\_utils.py", line 93, in collapse_excgroups
    raise exc
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\middleware\base.py", line 191, in __call__
    response = await self.dispatch_func(request, call_next)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\g4f\api\__init__.py", line 84, in authorization
    return await call_next(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\middleware\base.py", line 165, in call_next
    raise app_exc
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\middleware\base.py", line 151, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\middleware\exceptions.py", line 65, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\routing.py", line 756, in __call__
    await self.middleware_stack(scope, receive, send)
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\routing.py", line 776, in app
    await route.handle(scope, receive, send)
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\routing.py", line 297, in handle
    await self.app(scope, receive, send)
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\routing.py", line 77, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\starlette\routing.py", line 72, in app
    response = await func(request)
               ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\fastapi\routing.py", line 278, in app
    raw_response = await run_endpoint_function(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\fastapi\routing.py", line 191, in run_endpoint_function
    return await dependant.call(**values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\g4f\api\__init__.py", line 161, in chat_completions
    return JSONResponse((await response).to_json())
                         ^^^^^^^^^^^^^^
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\g4f\client\async_client.py", line 63, in iter_append_model_and_provider
    async for chunk in response:
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\g4f\client\async_client.py", line 37, in iter_response
    async for chunk in response:
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\g4f\Provider\needs_auth\OpenaiChat.py", line 419, in create_async_generator
    await raise_for_status(response)
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\g4f\requests\raise_for_status.py", line 28, in raise_for_status_async
    raise ResponseStatusError(f"Response {response.status}: {message}")
g4f.errors.ResponseStatusError: Response 401: {"detail":"Unauthorized"}

Any idea what does it mean? I tried to place the .har file inside:

C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\Scripts

But the error indicates something was unauthorized? I used a single space for the api key like you said (and tried also without it and I get the same error). That seems to be inline with the error that I get in OpenaiChat.py:

if response.status == 401:
                    raise MissingAuthError('Add a "api_key" or a .har file' if cls._api_key is None else "Invalid api key")

Thanks.

from gpt4free.

plia7 avatar plia7 commented on June 14, 2024

@hlohaus @iG8R Could it be a problem with my ChatGPT account? Could it be I got shadow banned or something where the .HAR that gets generated doesn't work anymore? Is it possible? Does the error I get indicates it can't find the .HAR file or could it be it does find it, but the content inside the file can't be used? Would there be a different error in that case?

The code seem to point to this error:

if response.status == 401:
                    raise MissingAuthError('Add a "api_key" or a .har file' if cls._api_key is None else "Invalid api key")

So I get status 401 unauthorized response.

Moreover, I noticed that if I go to the following URL/login to my chatgpt account:
https://platform.openai.com/playground/chat
Enter my question in the β€œUser” text box, just as you would if you were chatting on the regular chat.openai website, then press the submit button on the bottom left, I would get the message:

"You've reached your usage limit. See your [usage dashboard](https://platform.openai.com/account/usage) and [billing settings](https://platform.openai.com/account/billing) for more details. If you have further questions, please contact us through our help center at help.openai.com."

But other people told me they are able to use this too, and provided a screenshot:

https://imgur.com/a/P4YeuA4

So I wonder if this is related and part of the root cause to the problem that I experience with the .har file (401 unauthorized response), what do you think?

Thanks.

from gpt4free.

plia7 avatar plia7 commented on June 14, 2024

@hlohaus @iG8R Ok in one environment, I was able to get this to work with a new .HAR I just downloaded, so it must be something with my other two environments. It doesn't seem like a problem with my ChatGPT account.

But why in two environments it would get screwy like that out of the blue? Everything was working fine prior to that, it doesn't make any sense.

@hlohaus It doesn't make sense that I need to re-create the environment, re-install python and g4f just to get this to work? Why would it work in one environment with the same .HAR file but then it would fail in another environment with the same .HAR file?

Could you please fix it, so it's environment agnostic and never fails? Is there a way to force it to use the .HAR file somehow? Can I modify some code to tell it to use the file directly?

Could you please direct me what to change and try it and see if it fixes the problem? I can modify:

C:\users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\g4f\Provider\needs_auth\OpenaiChat.py

Just tell me what to change to force it to read my .HAR file that's located in:

C:\Users\me\Documents\chat.openai.com.har

Thanks.

from gpt4free.

hlohaus avatar hlohaus commented on June 14, 2024

Please enable the logging or debug mode. This will allow you to view the .har files that are loaded in the log.

from gpt4free.

plia7 avatar plia7 commented on June 14, 2024

Please enable the logging or debug mode. This will allow you to view the .har files that are loaded in the log.

How do I do that?
I run my script like this:

python3 chatgpt.py

So where do I enable logging for it?

Thanks.

from gpt4free.

iG8R avatar iG8R commented on June 14, 2024

@plia7

So where do I enable logging for it?

Read once more my post #1896 (comment) and repeat it exactly as it was described.

from gpt4free.

plia7 avatar plia7 commented on June 14, 2024

@plia7

So where do I enable logging for it?

Read once more my post #1896 (comment) and repeat it exactly as it was described.

@iG8R Sorry but I don't want to recreate my environment from scratch, I have other things there that I want to keep.

from gpt4free.

iG8R avatar iG8R commented on June 14, 2024

@plia7
All these steps do not change your environment in any way, which is why I wrote them there. Once everything is done, all you have to do is delete the g4f directory.
Also there you will find the answer to the question "So where do I enable logging?".

from gpt4free.

plia7 avatar plia7 commented on June 14, 2024

@plia7

All these steps do not change your environment in any way, which is why I wrote them there. Once everything is done, all you have to do is delete the g4f directory.

Also there you will find the answer to the question "So where do I enable logging?".

I'm running it on a linux x86 emulator which is very slow to uninstall/install g4f.

from gpt4free.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.