diff options
author | H Lohaus <hlohaus@users.noreply.github.com> | 2024-04-05 21:03:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-05 21:03:12 +0200 |
commit | c791012b218667e1449e1224014f05213fb1fc9c (patch) | |
tree | b4ab92cd92c386b86cdeea1b4d80d3eec43eb02f /g4f/requests | |
parent | Fix Gemini Proxy Connect call failed (#1768) (diff) | |
parent | Add authless OpenaiChat (diff) | |
download | gpt4free-c791012b218667e1449e1224014f05213fb1fc9c.tar gpt4free-c791012b218667e1449e1224014f05213fb1fc9c.tar.gz gpt4free-c791012b218667e1449e1224014f05213fb1fc9c.tar.bz2 gpt4free-c791012b218667e1449e1224014f05213fb1fc9c.tar.lz gpt4free-c791012b218667e1449e1224014f05213fb1fc9c.tar.xz gpt4free-c791012b218667e1449e1224014f05213fb1fc9c.tar.zst gpt4free-c791012b218667e1449e1224014f05213fb1fc9c.zip |
Diffstat (limited to 'g4f/requests')
-rw-r--r-- | g4f/requests/raise_for_status.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/g4f/requests/raise_for_status.py b/g4f/requests/raise_for_status.py index 9e8e141c..0e91505e 100644 --- a/g4f/requests/raise_for_status.py +++ b/g4f/requests/raise_for_status.py @@ -13,12 +13,17 @@ class CloudflareError(ResponseStatusError): def is_cloudflare(text: str) -> bool: return '<div id="cf-please-wait">' in text or "<title>Just a moment...</title>" in text +def is_openai(text: str) -> bool: + return "<p>Unable to load site</p>" in text + async def raise_for_status_async(response: Union[StreamResponse, ClientResponse], message: str = None): if response.status in (429, 402): raise RateLimitError(f"Response {response.status}: Rate limit reached") message = await response.text() if not response.ok and message is None else message if response.status == 403 and is_cloudflare(message): raise CloudflareError(f"Response {response.status}: Cloudflare detected") + elif response.status == 403 and is_openai(message): + raise ResponseStatusError(f"Response {response.status}: Bot are detected") elif not response.ok: raise ResponseStatusError(f"Response {response.status}: {message}") |