xtekky / gpt4free

The official gpt4free repository | various collection of powerful language models
https://g4f.ai
GNU General Public License v3.0
61.12k stars 13.32k forks source link

Cloudflare detected #2235

Closed nitsik closed 1 month ago

nitsik commented 1 month ago
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?

TheFirstNoob commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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: https://github.com/xtekky/gpt4free/issues/1815

github-actions[bot] commented 1 month ago

Bumping this issue because it has been open for 7 days with no activity. Closing automatically in 7 days unless it becomes active again.

github-actions[bot] commented 1 month ago

Closing due to inactivity.