Прокси-серверы Socks5 вызывают «Соединение неожиданно закрылось» и «[Errno 104] Соединение сброшено узлом» - PullRequest
0 голосов
/ 05 января 2020

Я пытаюсь подключиться к socks прокси в запросах. Я следовал за этим топи c, и это не помогает. Я установил pysocks и requests[socks]. Я тоже думал, что это может быть из-за прокси. Итак, я написал программу, которая проверяет список прокси одновременно. Нет проблем с http прокси. Когда я пытаюсь подключиться к прокси Socks, я получаю следующие ошибки:

SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e471e748>: Failed to establish a new connection: Connection closed unexpectedly',))

и

SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e40c9198>: Failed to establish a new connection: [Errno 104] Connection reset by peer',))

Вот мой код:

import requests
import concurrent.futures
import os


def proxyformated(proxy):
    # for example it gets '192.168.1.1:9050' and returns
    # {'http': 'socks5:192.168.1.1:9050//', 'https': 'socks5://192.168.1.1:9050'}
    return {'http': f'socks5://{proxy}', 'https': f'socks5://{proxy}'}


def check(proxy):
    print(f"trying {proxy}")
    proxy = proxyformated(proxy)
    try:
        r = requests.get('https://api.ipify.org', proxies=proxy)
        print(r.content)
    except Exception as e:
        print(e)


running_file_path = os.path.dirname(os.path.abspath(__file__))
os.chdir(running_file_path)

proxies = []
with open('proxies.txt', 'r') as proxies_file:
    proxies.extend(proxies_file.read().split("\n"))
    # getting proxies out of a txt file

with concurrent.futures.ThreadPoolExecutor() as executer:
    executer.map(check, proxies)

И вот вывод:

[Running] /usr/bin/python3 -u "/home/jackson/Desktop/socksproxychecker.py"
trying 138.197.157.44:1080
trying 138.197.157.60:1080
trying 138.197.157.32:1080
trying 138.197.145.103:1080
trying 138.197.157.45:1080
trying 67.205.149.230:1080
trying 162.243.108.129:1080
trying 67.205.132.241:1080
trying 198.199.120.102:1080
trying 67.205.174.209:1080
trying 162.243.107.120:1080
trying 159.203.91.6:1080
trying 159.203.166.41:1080
trying 165.227.215.62:1080
trying 67.205.146.29:1080
trying 165.227.215.71:1080
trying 162.243.108.141:1080
trying 174.138.54.49:1080
trying 162.243.108.161:1080
trying 50.116.38.201:9022
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e46f5668>: Failed to establish a new connection: [Errno 111] Connection refused',))
trying 66.33.209.81:4095
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e47101d0>: Failed to establish a new connection: [Errno 110] Connection timed out',))
trying 138.197.204.55:1080
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e47364e0>: Failed to establish a new connection: [Errno 104] Connection reset by peer',))
trying 138.68.41.90:1080
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e47436d8>: Failed to establish a new connection: [Errno 104] Connection reset by peer',))
trying 138.68.24.145:1080
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e476a2b0>: Failed to establish a new connection: Connection closed unexpectedly',))
trying 45.55.27.15:1080
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e475ee10>: Failed to establish a new connection: Connection closed unexpectedly',))
trying 198.199.119.119:1080
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e479a320>: Failed to establish a new connection: Connection closed unexpectedly',))
trying 138.197.222.35:1080
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e4788550>: Failed to establish a new connection: Connection closed unexpectedly',))
trying 138.68.240.218:1080
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e476a470>: Failed to establish a new connection: [Errno 104] Connection reset by peer',))
trying 192.169.236.120:30562
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e4736b00>: Failed to establish a new connection: Connection closed unexpectedly',))
trying 166.62.116.194:22452
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e4736358>: Failed to establish a new connection: Connection closed unexpectedly',))
trying 45.55.9.218:1080
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e4774630>: Failed to establish a new connection: Connection closed unexpectedly',))
trying 138.68.173.29:1080
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e4788358>: Failed to establish a new connection: [Errno 104] Connection reset by peer',))
trying 138.68.161.14:1080
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e47524a8>: Failed to establish a new connection: [Errno 104] Connection reset by peer',))
trying 138.68.165.154:1080
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e479a080>: Failed to establish a new connection: Connection closed unexpectedly',))
trying 139.59.169.246:1080
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e47a8fd0>: Failed to establish a new connection: Connection closed unexpectedly',))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e4710f60>: Failed to establish a new connection: [Errno 104] Connection reset by peer',))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e4736160>: Failed to establish a new connection: [Errno 104] Connection reset by peer',))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e4752358>: Failed to establish a new connection: [Errno 104] Connection reset by peer',))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e4feaf28>: Failed to establish a new connection: Connection closed unexpectedly',))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e409fa20>: Failed to establish a new connection: [Errno 104] Connection reset by peer',))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e40ad208>: Failed to establish a new connection: Connection closed unexpectedly',))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e4743908>: Failed to establish a new connection: Connection closed unexpectedly',))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e4752e80>: Failed to establish a new connection: Connection closed unexpectedly',))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e4788080>: Failed to establish a new connection: Connection closed unexpectedly',))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e4710668>: Failed to establish a new connection: Connection closed unexpectedly',))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e40ad9b0>: Failed to establish a new connection: [Errno 104] Connection reset by peer',))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e471edd8>: Failed to establish a new connection: Connection closed unexpectedly',))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e40c9198>: Failed to establish a new connection: [Errno 104] Connection reset by peer',))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e40bc1d0>: Failed to establish a new connection: Connection closed unexpectedly',))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e40bc9b0>: Failed to establish a new connection: Connection closed unexpectedly',))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e472aa58>: Failed to establish a new connection: Connection closed unexpectedly',))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e46f5550>: Failed to establish a new connection: Connection closed unexpectedly',))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e471e748>: Failed to establish a new connection: Connection closed unexpectedly',))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f15e409f278>: Failed to establish a new connection: [Errno 110] Connection timed out',))

[Done] exited with code=0 in 1221.386 seconds

Я получаю свои прокси на этом сайте

ОБНОВЛЕНИЕ 1:
Я получаю свои прокси-носки с этого сайта и вышеупомянутая проблема возникает, когда я использую иностранные носки, но когда я попробовал прокси носков в Иране (стране, в которой я живу), это работает. Тем не менее, есть много прокси, которые делают ошибки. Так почему вы думаете, что я не могу подключиться к чужим носкам? Есть ли шанс, что правительство может заблокировать их всех?

[Running] /usr/bin/python3 -u "/home/jackson/Desktop/socksproxychecker.py"
trying 37.32.31.205:1080
trying 81.12.91.156:4145
trying 88.135.41.160:4145
trying 37.32.9.103:1085
trying 79.132.201.203:4145
trying 188.121.106.74:1080
trying 88.135.43.117:4145
trying 37.32.26.81:54086
trying 188.136.204.139:4145
trying 94.139.163.77:4145
trying 81.12.91.155:4145
trying 188.136.143.82:47449
trying 188.136.143.85:47449
trying 37.32.125.58:38859
trying 46.209.105.26:34637
trying 37.32.125.241:56870
trying 37.32.10.169:1080
trying 188.121.111.6:1085
trying 91.98.117.144:38984
trying 185.23.131.237:31944
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f94083ef828>: Failed to establish a new connection: [Errno 113] No route to host',))
trying 188.240.196.66:41599
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f9408148ba8>: Failed to establish a new connection: Connection closed unexpectedly',))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f94083d2048>: Failed to establish a new connection: Connection closed unexpectedly',))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f9408401470>: Failed to establish a new connection: Connection closed unexpectedly',))
trying 185.126.133.164:4145
trying 37.235.28.42:40520
trying 37.32.12.52:1080
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f94083cd080>: Failed to establish a new connection: Connection closed unexpectedly',))
trying 91.98.153.38:4145
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f9408401e48>: Failed to establish a new connection: [Errno 111] Connection refused',))
trying 91.98.147.70:4145
b'94.139.163.77'
trying 5.160.66.114:30606
b'91.98.147.70'
trying 91.98.20.116:4145
b'81.12.91.155'
trying 37.32.23.74:1085
b'37.32.23.74'
trying 85.133.143.35:4145
b'79.132.201.203'
trying 185.134.99.66:51327
b'81.12.91.156'
trying 88.135.46.48:11337
b'37.32.125.241'
trying 79.132.205.34:61731
b'37.32.9.103'
trying 88.135.43.186:4145
b'37.32.12.52'
trying 91.98.94.31:4145
b'79.132.205.34'
b'91.98.117.144'
b'46.209.105.26'
b'88.135.41.160'
b'185.23.131.237'
b'185.134.99.66'
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f940839a0b8>, 'Connection to api.ipify.org timed out. (connect timeout=40)'))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f940839a6d8>, 'Connection to api.ipify.org timed out. (connect timeout=40)'))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f94083c1080>, 'Connection to api.ipify.org timed out. (connect timeout=40)'))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f94083ef5f8>, 'Connection to api.ipify.org timed out. (connect timeout=40)'))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f940839af98>, 'Connection to api.ipify.org timed out. (connect timeout=40)'))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f9408148908>, 'Connection to api.ipify.org timed out. (connect timeout=40)'))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f94083b4cc0>, 'Connection to api.ipify.org timed out. (connect timeout=40)'))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f9408164358>, 'Connection to api.ipify.org timed out. (connect timeout=40)'))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f940840d6d8>, 'Connection to api.ipify.org timed out. (connect timeout=40)'))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f9408164fd0>, 'Connection to api.ipify.org timed out. (connect timeout=40)'))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f940840d400>, 'Connection to api.ipify.org timed out. (connect timeout=40)'))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f940a428278>, 'Connection to api.ipify.org timed out. (connect timeout=40)'))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f940a428e10>, 'Connection to api.ipify.org timed out. (connect timeout=40)'))
SOCKSHTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f9408157ef0>, 'Connection to api.ipify.org timed out. (connect timeout=40)'))

[Done] exited with code=0 in 49.379 seconds
...