D
D
Dmitry Matveev2018-01-27 00:20:20
Python
Dmitry Matveev, 2018-01-27 00:20:20

Why does a request fail through a proxy with IPv6?

Hello, I can't figure out how to solve the problem. I bought a private proxy located in Germany. This proxy has IPv6 and uses SOCKS5. The site I'm making a request to supports IPv6.

import requests

responce = requests.get('https://yandex.ru/internet/',
                        proxies={'https': 'socks5://ChbfSD:[email protected]:18791'})
print(responce.text)

The following error occurs:
Traceback (most recent call last):
  File "C:\Users\Dmitry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\socks.py", line 851, in connect
    negotiate(self, dest_addr, dest_port)
  File "C:\Users\Dmitry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\socks.py", line 497, in _negotiate_SOCKS5
    self, CONNECT, dest_addr)
  File "C:\Users\Dmitry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\socks.py", line 578, in _SOCKS5_request
    raise SOCKS5Error("{0:#04x}: {1}".format(status, error))
socks.SOCKS5Error: 0x05: Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Dmitry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\contrib\socks.py", line 88, in _new_conn
    **extra_kw
  File "C:\Users\Dmitry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\socks.py", line 262, in create_connection
    raise err
  File "C:\Users\Dmitry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\socks.py", line 252, in create_connection
    sock.connect((remote_host, remote_port))
  File "C:\Users\Dmitry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\socks.py", line 100, in wrapper
    return function(*args, **kwargs)
  File "C:\Users\Dmitry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\socks.py", line 855, in connect
    raise GeneralProxyError("Socket error", error)
socks.GeneralProxyError: Socket error: 0x05: Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Dmitry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "C:\Users\Dmitry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 346, in _make_request
    self._validate_conn(conn)
  File "C:\Users\Dmitry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 850, in _validate_conn
    conn.connect()
  File "C:\Users\Dmitry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connection.py", line 284, in connect
    conn = self._new_conn()
  File "C:\Users\Dmitry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\contrib\socks.py", line 110, in _new_conn
    "Failed to establish a new connection: %s" % error
urllib3.exceptions.NewConnectionError: <urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x0616C650>: Failed to establish a new connection: 0x05: Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Dmitry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\adapters.py", line 440, in send
    timeout=timeout
  File "C:\Users\Dmitry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 639, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "C:\Users\Dmitry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\util\retry.py", line 388, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: SOCKSHTTPSConnectionPool(host='yandex.ru', port=443): Max retries exceeded with url: /internet/ (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x0616C650>: Failed to establish a new connection: 0x05: Connection refused',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/Dmitry/Desktop/GitHub/Python/Test/main.py", line 4, in <module>
    proxies={'https': 'socks5://ChbfSD:[email protected]:18791'})
  File "C:\Users\Dmitry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Users\Dmitry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\Dmitry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\Dmitry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\Dmitry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\adapters.py", line 508, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: SOCKSHTTPSConnectionPool(host='yandex.ru', port=443): Max retries exceeded with url: /internet/ (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x0616C650>: Failed to establish a new connection: 0x05: Connection refused',))

Can you help me figure out what is wrong and how to fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Dubrovin, 2018-01-27
@DmMatveev

When using socks5://, the name is resolved locally, and the request flies to socks with an IP address, and most likely, this is IPv4.
In order for the name to fly away in socks, you must use socks5h://

D
Dimonchik, 2018-01-27
@dimonchik2013

check on another url
if everything is ok - it's in Yandex, if not -
check the sockets in the proxy again

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question