Reputation: 7
Im just trying to use all my proxies to send a request, but only one proxy is used.
this is my code:
import requests
import random
import string
import random
from proxy_requests import ProxyRequests
proxies = {'https': 'https://104.148.46.2:3121',
'https': 'https://134.19.254.2:21231',
'https': 'https://45.76.222.196:8118',
'https': 'https://103.87.207.188:59064',
'https': 'https://182.74.40.146:30909',
'https': 'https://5.196.132.115:3128',
'https': 'https://200.142.120.90:56579',
'https': 'https://24.172.82.94:53281',
'https': 'https://213.141.93.60:32125',
'https': 'https://167.71.6.78:3128',
'https': 'https://202.166.205.78:58431',
'https': 'https://37.82.13.84:8080',
'https': 'https://132.255.23.157:3128'}
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36
OPR/63.0.3368.71'}
while True:
with requests.Session() as s:
register_data = {"POST":"CENSORED"}
url = 'CENSORED'
r = s.post(url, json=register_data, proxies = proxies)
print(r.content)
print (proxies)
the output is:
b'"CENSORED"'
{'https': 'https://132.255.23.157:3128'}
b'"CENSORED"'
{'https': 'https://132.255.23.157:3128'}
b'"CENSORED"'
{'https': 'https://132.255.23.157:3128'}
And i need output like this:
b'"CENSORED"'
{'https': 'https://202.166.205.78:58431'}
b'"CENSORED"'
{'https': 'https://103.87.207.188:59064'}
b'"CENSORED"'
{'https': 'https://132.255.23.157:3128'}
I tried to use proxy request module(proxy_requests), but i need to use custom proxies.
Upvotes: 0
Views: 1781
Reputation: 555
You are creating dictionary of proxies, which is wrong. 'https'
is a key and there will only one key with name https. you are assigning value 'https://132.255.23.157:3128'
to 'https'
at last, so every time you print proxies
you will get {'https': 'https://132.255.23.157:3128'}
you have to create list of dictionary for proxies
to get your desired output.
import requests
import random
proxies = [{'https': 'https://104.148.46.2:3121'}, {'https': 'https://134.19.254.2:21231'}, {'https': 'https://45.76.222.196:8118'}, {'https': 'https://103.87.207.188:59064'}, {'https': 'https://182.74.40.146:30909'}, {'https': 'https://5.196.132.115:3128'}, {'https': 'https://200.142.120.90:56579'}, {'https': 'https://24.172.82.94:53281'}, {'https': 'https://213.141.93.60:32125'}, {'https': 'https://167.71.6.78:3128'}, {'https': 'https://202.166.205.78:58431'}, {'https': 'https://37.82.13.84:8080'}, {'https': 'https://132.255.23.157:3128'}]
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36OPR/63.0.3368.71'}
while True:
with requests.Session() as s:
register_data = {"POST":"CENSORED"}
url = 'CENSORED'
r = s.post(url, json=register_data, proxies = random.choice(proxies))
print(r.content)
print (proxies)
Upvotes: 1