Chatgpt登陆后一直在转圈请求429错误的解决办法

Chatgpt登陆后一直在转圈请求429错误的解决办法

如果您使用ChatGPT登陆后遇到了持续转圈或请求429错误,可能是由于请求次数过多导致的限制。为了解决这个问题,可以尝试以下几个方法:

  1. 等待一段时间后再次尝试登陆。由于请求次数过多,ChatGPT可能会限制您的请求,因此等待一段时间后再次尝试登陆可能会解决问题。

  2. 检查您的网络连接。如果您的网络连接不稳定或网络速度较慢,可能会导致ChatGPT无法正常工作。请确保您的网络连接良好,并且网络速度足够快。

  3. 尝试清除浏览器缓存。有时候浏览器缓存可能会导致问题,尝试清除浏览器缓存后再次尝试登陆可能会解决问题。

我使用了指数退避重试解决了问题

1、创建一个python脚本

# imports
import random
import time

import openai


# define a retry decorator
def retry_with_exponential_backoff(
        func,
        initial_delay: float = 1,
        exponential_base: float = 2,
        jitter: bool = True,
        max_retries: int = 10,
        errors: tuple = (openai.error.RateLimitError,),
):
    """Retry a function with exponential backoff."""

    def wrapper(*args, **kwargs):
        # Initialize variables
        num_retries = 0
        delay = initial_delay

        # Loop until a successful response or max_retries is hit or an exception is raised
        while True:
            try:
                return func(*args, **kwargs)

            # Retry on specific errors
            except errors as e:
                # Increment retries
                num_retries += 1

                # Check if max retries has been reached
                if num_retries > max_retries:
                    raise Exception(
                        f"Maximum number of retries ({
      
      max_retries}) exceeded."
                    )

                # Increment the delay
                delay *= exponential_base * (1 + jitter * random.random())

                # Sleep for the delay
                time.sleep(delay)

            # Raise exceptions for any errors not specified
            except Exception as e:
                raise e

    return wrapper


@retry_with_exponential_backoff
def completions_with_backoff(**kwargs):
    return openai.Completion.create(**kwargs)

注:此脚本中,要下载openai第三方包
使用命令如下:

pip install openai -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

下载完成后需要注意urllib3的版本

pip install urllib3==1.25.11

再次运行上次代码,若无报错,重新刷新openai界面,则无429错误

若上面不成功,在试试下面的

import openai
from openai.error import RateLimitError
import backoff

@backoff.on_exception(backoff.expo, RateLimitError)
def completions_with_backoff(**kwargs):
    response = openai.Completion.create(**kwargs)
    return response

尝试多运行几次

还有下面这个方法也可以试试

import backoff  
import openai 

openai.api_key= ''  # 你的OpenAI API
@backoff.on_exception(backoff.expo, openai.error.RateLimitError)
def completions_with_backoff(**kwargs):
    return openai.Completion.create(**kwargs)


completions_with_backoff(model="text-davinci-002", prompt="Once upon a time,")

还有就是先关掉代理,刷新页面,在切换其他代理,刷新一下可以了
若还是不行,就等几个小时自动就好了

猜你喜欢

转载自blog.csdn.net/weixin_44727769/article/details/130558619