[Python] System-level rate limit exceeded in Python despite using multiple proxies, each...

Discussão em 'Python' iniciado por Stack, Outubro 6, 2024.

  1. Stack

    Stack Membro Participativo

    I’m encountering an issue with rate limits in my Python code, even though I’m using multiple proxies and ensuring that each proxy is called only once. Despite this, I keep receiving the error: "System-level rate limit exceeded."

    Here’s an overview of my setup:

    I have a list of proxies, and I’m using each proxy only for a single request, each proxy only call once (but using thread to call many request at a time).

    However, after a few requests, I still get the rate limit error. Here is a simplified version of my Python code:

    def _request(self, method, uri, timeout=5, auth=True, params=None):



    uri_path = uri
    data_json = ''
    if method in ['GET', 'DELETE']:
    if params:
    strl = []
    for key in sorted(params):
    strl.append("{}={}".format(key, params[key]))
    data_json += '&'.join(strl)
    uri += '?' + data_json
    uri_path = uri

    else:
    if params:
    data_json = json.dumps(params)

    uri_path = uri + data_json

    headers = {}
    if auth:
    now_time = int(time.time()) * 1000
    str_to_sign = str(now_time) + method + uri_path
    sign = base64.b64encode(
    hmac.new(self.secret.encode('utf-8'), str_to_sign.encode('utf-8'), hashlib.sha256).digest())
    if self.is_v1api:
    headers = {
    "KC-API-SIGN": sign,
    "KC-API-TIMESTAMP": str(now_time),
    "KC-API-KEY": self.key,
    "KC-API-PASSPHRASE": self.passphrase,
    "Content-Type": "application/json"
    }
    else:
    passphrase = base64.b64encode(
    hmac.new(self.secret.encode('utf-8'), self.passphrase.encode('utf-8'), hashlib.sha256).digest())
    headers = {
    "KC-API-SIGN": sign,
    "KC-API-TIMESTAMP": str(now_time),
    "KC-API-KEY": self.key,
    "KC-API-PASSPHRASE": passphrase,
    "Content-Type": "application/json",
    "KC-API-KEY-VERSION": "2"
    }
    headers["User-Agent"] = "kucoin-python-sdk/"+version
    url = urljoin(self.url, uri)

    proxy_dict = {'http': self.cl_proxy, 'https': self.cl_proxy} #if self.cl_proxy else None
    #print (url,proxy_dict)
    if method in ['GET', 'DELETE']:
    r = requests.request(method, url, headers=headers, timeout=timeout, proxies=proxy_dict)
    else:
    r = requests.request(method, url, headers=headers, data=data_json, timeout=timeout, proxies=proxy_dict)

    if ("System-level rate limit exceeded"):
    s = str(url) + str(self.key)+ str(proxy_dict ) + str(r.status_code)
    print (s)

    Continue reading...

Compartilhe esta Página