mbroton / chatgpt-api

ChatGPT HTTP API Client and CLI
MIT License
123 stars 13 forks source link

chatgpt.exceptions.ForbiddenException: Access forbidden. #18

Open Shuangcheng-Ni opened 1 year ago

Shuangcheng-Ni commented 1 year ago

chatgpt-api version: 0.2.1
My code:

with ChatGPT(session_token='...', response_timeout=30) as chatter:
    ask = input('ask:')
    print('ans:', chatter.send_message(ask).content)

The exception it causes:

Traceback (most recent call last):
    File "...", line ..., in <module>
        with ChatGPT(session_token='...', response_timeout=30) as chatter:
    File "/home/user/.local/lib/python3.8/site-packages/chatgpt/api.py", line 68, in __enter__
        self.authenticate()
    File "/home/user/.local/lib/python3.8/site-packages/chatgpt/api.py", line 81, in authenticate
        raise ForbiddenException(
chatgpt.exceptions.ForbiddenException: Access forbidden. It may indicate that something had changed on ChatGPT side. See https://github.com/mbroton/chatgpt-api/issues

It seems that the chatgpt server has upgraded its security policy, which might cause authentication failure.

bensmrs commented 1 year ago

Yup, they put a Cloudflare anti-DDOS frontend. I think we have to resort to Selenium-like trickeries to be able to bypass it…

danielthedank commented 1 year ago

Good luck. Needles to say a command line chatGPT is a game changer. Salute

efJerryYang commented 1 year ago

The same problem. Maybe can use the methods applied in this repo https://github.com/acheong08/ChatGPT, which is great enough for terminal use with xvfb. But that one does not contain a good tui so I hope this project can continue improving.

mbroton commented 1 year ago

I'm aware of this problem. I'll try to make it work in a day or so.

mbroton commented 1 year ago

I made it works, but I need to test it and adapt to the CLI. Unfortunately, ChatGPT is currently overloaded, so I have to pause my work.

mbroton commented 1 year ago

My changes from yesterday don't work anymore. It's really time consuming to keep it up to date with OpenAI's changes and I can't afford it. I'm thinking about archiving the repository. If someone wants to contribute or start working on this project, feel free to do so.

Shuangcheng-Ni commented 1 year ago

My changes from yesterday don't work anymore. It's really time consuming to keep it up to date with OpenAI's changes and I can't afford it. I'm thinking about archiving the repository. If someone wants to contribute or start working on this project, feel free to do so.

I've found a repository that still works. It resorts to playwright trickeries to bypass the Cloudflare frontend. Maybe you can refer to it.