0

I'm trying to create a program that checks for username availability against an API. However, I get rate limited after about 300 requests. To bypass this I thought of using rotating proxies after 100 requests but that didn't work as I'm getting 429 errors. Does anyone know another method or knows what I'm doing wrong?

(OLD) My attempt to bypass it:

    proxy = ''
    proxyFile = open(f'external/proxies.txt', 'r')
    proxyList = [line.split(',') for line in proxyFile.readlines()]
...

    def proxies(self):
        try: 
            if self.proxyCount > 0:
                self.proxyCount += 1
            proxy = self.proxyList[self.proxyCount]
            return proxy
        except:
            print(f"{Fore.LIGHTBLACK_EX}[+]{Fore.RESET} No more proxies")

    def checkAccounts(self):
        while not self.usernames.empty():
            name = self.usernames.get(); self.usernames.put(name)
            url = f"https://public-ubiservices.ubi.com/v3/profiles?nameOnPlatform={name}&platformType=uplay"
            try:         
                r = self.session.get(url, headers=self.headers)
                
                try:
                    if self.checkedCount % 100 == 0:
                        self.proxies()
                except:
                    pass

                ctypes.windll.kernel32.SetConsoleTitleW(f"Gx | Checked: {self.checkedCount}, Available: {self.availableCount}, Errors: {self.errorCount}")
                if r.status_code == 200:

                    if len(r.json()['profiles']) != 0:
                        print(f"{Fore.LIGHTBLACK_EX}[+]{Fore.RESET} Taken:          {name}")
                        self.checkedCount += 1
                        
                    else:  
                        print(f"{Fore.LIGHTBLACK_EX}[+]{Fore.RESET} Available:      {name}")
                        self.availableCount += 1
                        self.checkedCount += 1

                else:
                    print(f"{Fore.LIGHTBLACK_EX}[+]{Fore.RESET} Error:          Check errors.txt")
                    with open('external/errors.txt', "a") as errorFile:
                        errorFile.write(f'{self.currentTime} | Checking error {r.status_code}, Error message: {r.text}\n')

Edit1 (Proxy function now works, but still getting rate limited):

url = f"https://public-ubiservices.ubi.com/v3/profiles?nameOnPlatform={name}&platformType=uplay"
try:         
    r = requests.get(url, headers=self.headers, proxies=self.proxy)
    try:
        if self.checkedCount % 100 == 0:
        self.proxies()
    except:
        pass
...

if r.status_code == 429:
    self.errorCount += 1
    print(f"{Fore.LIGHTBLACK_EX}[+]{Fore.RESET} Error:          Rate limited")
    self.proxies()

...
    def proxies(self):
        try: 
            if self.proxyCount > 0:
                self.proxyCount += 1
            proxy = random.choice(self.proxyList)
            print(proxy)
            return proxy
        except:
            pass

Output of edit1

['14.140.131.82:3128\n']
[+] Error:          Rate limited
['89.133.95.177:18080\n']
['36.91.45.10:51672\n']
[+] Error:          Rate limited
['36.91.45.10:51672\n']
['85.214.65.246:80\n']
[+] Error:          Rate limited
  • It doesn't look like `self.proxies` does anything? You call `self.proxies()` but you never do anything with the return value. – larsks Oct 24 '21 at 12:16
  • @larsks I changed a few things around and the proxies now seem to rotate. However, the proxies don't get used in the requests being sent. Can you figure why? –  Oct 24 '21 at 12:41
  • You are not setting `self.proxy`: `return proxy` → `self.proxy = {'https': proxy}` – aaron Oct 24 '21 at 13:20
  • I’m voting to close this question because while similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. – aaron Nov 07 '21 at 13:39

0 Answers0