Zai-Kun / reverse-engineered-chatgpt

Unofficial reverse-engineered ChatGPT API in Python
Apache License 2.0
240 stars 31 forks source link

Checking your browser before accessing #7

Closed 3mora2 closed 9 months ago

3mora2 commented 9 months ago

get error Checking your browser before accessing "chat.openai.com". as html when await self.update_auth_token(self.session_token) return html

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.3.2\plugins\python-ce\helpers\pydev\pydevconsole.py", line 364, in runcode
    coro = func()
           ^^^^^^
  File "<input>", line 1, in <module>
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.3.2\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.3.2\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:\Users\ammar\Downloads\reverse-engineered-chatgpt-main\tesr\1.py", line 32, in <module>
    reply = asyncio.run(main(prompt))
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ammar\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\ammar\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ammar\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\ammar\Downloads\reverse-engineered-chatgpt-main\tesr\1.py", line 17, in main
    async with ChatGPT(
  File "C:\Users\ammar\Downloads\reverse-engineered-chatgpt-main\re_gpt\chatgpt.py", line 51, in __aenter__
    await self.update_auth_token(self.session_token)
  File "C:\Users\ammar\Downloads\reverse-engineered-chatgpt-main\re_gpt\chatgpt.py", line 217, in update_auth_token
    response_json = response.json()
                    ^^^^^^^^^^^^^^^
  File "C:\Users\ammar\Downloads\reverse-engineered-chatgpt-main\venvtest\Lib\site-packages\curl_cffi\requests\models.py", line 64, in json
    return loads(self.content, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ammar\AppData\Local\Programs\Python\Python311\Lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ammar\AppData\Local\Programs\Python\Python311\Lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ammar\AppData\Local\Programs\Python\Python311\Lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Zai-Kun commented 9 months ago

It is working perfectly fine for me. Perhaps the issue lies with the 'curl_cffi' library. Try reinstalling it using the following method:

pip uninstall curl_cffi
pip install curl_cffi==0.5.9
3mora2 commented 9 months ago

thanks, it work now

phamxtien commented 8 months ago

Please help! I get the same above error. OS: Ubuntu Python: 3.11 curl_cffi: curl_cffi-0.5.9 My code is

def revChatGPT(prompt, id=''):
    from revChatGPT import AsyncChatGPT

    session_token = "__Secure-next-auth.session-token here" 
    if id == '': conversation_id = None # conversation ID here
    else: conversation_id = id

    if sys.version_info >= (3, 8) and sys.platform.lower().startswith("win"):
        asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

    async def main():
        ans = ''
        async with AsyncChatGPT(session_token=session_token) as chatgpt:
            if conversation_id:
                conversation = chatgpt.get_conversation(conversation_id)
            else:
                conversation = chatgpt.create_new_conversation()

            async for message in conversation.chat(prompt):
                # print(message["content"], flush=True, end="")
                ans = ans + message["content"]
            return ans

    ans = asyncio.run(main())
    return {'RESULT': True, 'ID': '', 'DATA': ans}

print(revChatGPT('hi'))
Zai-Kun commented 8 months ago

Did you try reinstalling the curl_cffi LIB?

pip uninstall curl_cffi
pip install curl_cffi==0.5.9

And you should use SyncChatGPT instead of AsyncChatGPT if you are unfamiliar with async programming in Python.

phamxtien commented 8 months ago

Did you try reinstalling the curl_cffi LIB?

pip uninstall curl_cffi
pip install curl_cffi==0.5.9

And you should use SyncChatGPT instead of AsyncChatGPT if you are unfamiliar with async programming in Python.

I install curl_cffi==0.5.9

python3 -m pip show curl-cffi
Name: curl-cffi
Version: 0.5.9
Summary: libcurl ffi bindings for Python, with impersonation support
Home-page: 
Author: 
Author-email: Yifei Kong <kong@yifei.me>
License: MIT License

And use SyncChatGPT instead of AsyncChatGPT with the code:

def revChatGPT(prompt, id=''):
    from re_gpt import SyncChatGPT

    session_token = "__Secure-next-auth.session-token here"    # I replace this with my __Secure-next-auth.session-token
    if id == '': conversation_id = None # conversation ID here
    else: conversation_id = id

    with SyncChatGPT(session_token=session_token) as chatgpt:
        if conversation_id:
            conversation = chatgpt.get_conversation(conversation_id)
        else:
            conversation = chatgpt.create_new_conversation()

        for message in conversation.chat(prompt):
            print(message["content"], flush=True, end="")

when call revChatGPT('hi') it returns:

Traceback (most recent call last):
  File "/usr/lib/python3.11/code.py", line 90, in runcode
    exec(code, self.locals)
  File "<console>", line 1, in <module>
  File "..../libs.py", line 468, in revChatGPT
    with SyncChatGPT(session_token=session_token) as chatgpt:
  File "..../sync_chatgpt.py", line 292, in __enter__
    self.auth_token = self.fetch_auth_token()
                      ^^^^^^^^^^^^^^^^^^^^^^^
  File "...../sync_chatgpt.py", line 368, in fetch_auth_token
    response_json = response.json()
                    ^^^^^^^^^^^^^^^
  File "....../curl_cffi/requests/models.py", line 64, in json
    return loads(self.content, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I tried to put accessToken to fetch_auth_token() and it return html source page.

Zai-Kun commented 8 months ago

Try updating curl_cffi to the latest version and try again. If the issue persists, follow these steps:

  1. Clone the repo using git: git clone https://github.com/Zai-Kun/reverse-engineered-chatgpt
  2. CD into the cloned repo: cd reverse-engineered-chatgpt
  3. Rename the sampleconfig.ini file to config.ini: mv sampleconfig.ini config.ini
  4. Edit the config.ini file and replace your __Secure-next-auth.session-token here with your actual session token
  5. Move the complex_example.py file from the examples folder to your current dir: mv examples/complex_example.py main.py
  6. Now, open up the re_gpt/sync_chatgpt.py file, and put this print statement at line 368: print(response.text)
  7. Run the main.py file: python3 main.py

If the issue persists, send the output of the print statement for debugging.

EDIT: And again, it works perfectly fine for me.

phamxtien commented 8 months ago

Try updating curl_cffi to the latest version and try again. If the issue persists, follow these steps:

  1. Clone the repo using git: git clone https://github.com/Zai-Kun/reverse-engineered-chatgpt
  2. CD into the cloned repo: cd reverse-engineered-chatgpt
  3. Rename the sampleconfig.ini file to config.ini: mv sampleconfig.ini config.ini
  4. Edit the config.ini file and replace your __Secure-next-auth.session-token here with your actual session token
  5. Move the complex_example.py file from the examples folder to your current dir: mv examples/complex_example.py main.py
  6. Now, open up the re_gpt/sync_chatgpt.py file, and put this print statement at line 368: print(response.text)
  7. Run the main.py file: python3 main.py

If the issue persists, send the output of the print statement for debugging.

EDIT: And again, it works perfectly fine for me.

Thanks for your help. Now, I can run the example.

phamxtien commented 8 months ago

Thanks @Zai-Kun , now I can make it works. Do you plan make login function with email, password ?

Zai-Kun commented 8 months ago

Do you plan make login function with email, password ?

Hmm, I might do it, I'm not sure.

sudoAlphaX commented 8 months ago

@Zai-Kun login function with credentials would be useful