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