chatgpt-api icon indicating copy to clipboard operation
chatgpt-api copied to clipboard

chatgpt.exceptions.ForbiddenException: Access forbidden.

Open Shuangcheng-Ni opened this issue 3 years ago • 7 comments

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.

Shuangcheng-Ni avatar Dec 12 '22 13:12 Shuangcheng-Ni

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

bensmrs avatar Dec 12 '22 15:12 bensmrs

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

danielthedank avatar Dec 13 '22 00:12 danielthedank

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.

efJerryYang avatar Dec 14 '22 03:12 efJerryYang

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

mbroton avatar Dec 14 '22 10:12 mbroton

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 avatar Dec 14 '22 14:12 mbroton

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.

mbroton avatar Dec 15 '22 11:12 mbroton

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.

Shuangcheng-Ni avatar Dec 15 '22 13:12 Shuangcheng-Ni