I'm trying to change proxies after x amount of requests for checking username availability against an api. However, my function for changing proxies doesn't seem to change the proxies in the requests I'm sending. In the proxy
function the proxies do change. Can anyone figure out why the proxies don't work in the requests sent?
(old) Code:
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 = random.choice(self.proxyList)
print('proxy in proxies function: ', proxy)
return proxy
except:
pass
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 = requests.get(url, headers=self.headers, proxies=self.proxy)
print('proxy in check function: ', self.proxy)
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:
self.checkedCount += 1
if len(r.json()['profiles']) != 0:
print(f"{Fore.LIGHTBLACK_EX}[+]{Fore.RESET} Taken: {name}")
else:
print(f"{Fore.LIGHTBLACK_EX}[+]{Fore.RESET} Available: {name}")
self.availableCount += 1
if r.status_code == 429:
self.errorCount += 1
print(f"{Fore.LIGHTBLACK_EX}[+]{Fore.RESET} Error: Rate limited")
self.proxies()
except Exception:
pass
Output:
[+] Taken: name
proxy in proxies function: ['222.74.202.234:80\n']
proxy in check function:
Previous post about the same topic
Edit1:
with open('external/proxies.txt', 'r') as f:
proxyList = [line.strip() for line in f]
...
def proxies(self):
if self.proxyCount > 0:
self.proxyCount += 1
proxy = random.choice(self.proxyList)
print(proxy)
return proxy
Output of Edit1:
85.214.65.246:80
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\Gibbo\AppData\Local\Programs\Python\Python39\lib\threading.py", line 954, in _bootstrap_inner
self.run()
File "C:\Users\Gibbo\AppData\Local\Programs\Python\Python39\lib\threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Gibbo\OneDrive\Bureaublad\[+] Projects\Main\[+] Ubi checker\ubichecker.py", line 66, in checkAccounts
r = requests.get(url, headers=self.headers, proxies=self.proxy)
File "C:\Users\Gibbo\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\Gibbo\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\Gibbo\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 532, in request
settings = self.merge_environment_settings(
File "C:\Users\Gibbo\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 710, in merge_environment_settings
no_proxy = proxies.get('no_proxy') if proxies is not None else None
AttributeError: 'str' object has no attribute 'get'