Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloudflare detected #2235

Open
nitsik opened this issue Sep 20, 2024 · 3 comments
Open

Cloudflare detected #2235

nitsik opened this issue Sep 20, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@nitsik
Copy link

nitsik commented Sep 20, 2024

from g4f.client import Client

client = Client()
response = client.chat.completions.create(
    model="gpt-4o",
    #messages=[{"role": "user", "content": "Какую модель ты используешь для ответа? gpt-4o?"}],
    messages=[{"role": "user", "content": "Нарисуй яблоко"}],
    provider="OpenaiChat",
)
print(response.choices[0].message.content)
python3.8 testGp4.py
Traceback (most recent call last):
  File "testGp4.py", line 4, in <module>
    response = client.chat.completions.create(
  File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/g4f/client/client.py", line 149, in create
    return response if stream else next(response)
  File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/g4f/client/client.py", line 75, in iter_append_model_and_provider
    for chunk in response:
  File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/g4f/client/client.py", line 38, in iter_response
    for idx, chunk in enumerate(response):
  File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/g4f/providers/base_provider.py", line 223, in create_completion
    yield loop.run_until_complete(await_callback(gen.__anext__))
  File "/root/.pyenv/versions/3.8.10/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/g4f/providers/base_provider.py", line 52, in await_callback
    return await callback()
  File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/g4f/Provider/needs_auth/OpenaiChat.py", line 376, in create_async_generator
    cls.default_model = cls.get_model(await cls.get_default_model(session, cls._headers))
  File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/g4f/Provider/needs_auth/OpenaiChat.py", line 197, in get_default_model
    await raise_for_status(response)
  File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/g4f/requests/raise_for_status.py", line 24, in raise_for_status_async
    raise CloudflareError(f"Response {response.status}: Cloudflare detected")
g4f.requests.raise_for_status.CloudflareError: Response 403: Cloudflare detected

Is it possible to decide?

@nitsik nitsik added the bug Something isn't working label Sep 20, 2024
@TheFirstNoob
Copy link

The official site is not available in the RU region. Use other providers. If you want to use the official site of GPT, use a proxy or VPN.

@nitsik
Copy link
Author

nitsik commented Sep 21, 2024

The official site is not available in the RU region. Use other providers. If you want to use the official site of GPT, use a proxy or VPN.

I'm using it from Bulgaria

@TheFirstNoob
Copy link

TheFirstNoob commented Sep 21, 2024

Hmm... try to recreate .har file and try pip install nodriver or webdriver (for chrome engine browsers) or curl_cffi.
https://github.com/xtekky/gpt4free/blob/main/docs/requirements.md
Check on browser how you connect to openai site maybe some packets have problem or wrong check-sum, or location detecting.
Try to update python to recommended g4f libs (3.10+ is recommended)

more info on 403 here: #1815

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants