Я пытаюсь запросить несколько адресов v3 .onion, но у меня возникают некоторые проблемы с этим. Я написал это
Код
import requests
from stem import Signal
from stem.control import Controller
from fake_useragent import UserAgent
session = requests.session()
session.headers = {
'User-Agent': UserAgent().random
}
session.proxies = {
'http': 'socks5h://127.0.0.1:9050',
'https': 'socks5h://127.0.0.1:9050'
}
url = 'https://www.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabgu.onion/'
with Controller.from_port(port = 9051) as c:
c.authenticate()
c.signal(Signal.NEWNYM)
print(session.get(url).text)
Ошибка
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/socks.py", line 809, in connect
negotiate(self, dest_addr, dest_port)
File "/usr/local/lib/python3.7/dist-packages/socks.py", line 444, in _negotiate_SOCKS5
self, CONNECT, dest_addr)
File "/usr/local/lib/python3.7/dist-packages/socks.py", line 533, in _SOCKS5_request
raise SOCKS5Error("{:#04x}: {}".format(status, error))
socks.SOCKS5Error: 0x01: General SOCKS server failure
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/contrib/socks.py", line 88, in _new_conn
**extra_kw
File "/usr/local/lib/python3.7/dist-packages/socks.py", line 209, in create_connection
raise err
File "/usr/local/lib/python3.7/dist-packages/socks.py", line 199, in create_connection
sock.connect((remote_host, remote_port))
File "/usr/local/lib/python3.7/dist-packages/socks.py", line 47, in wrapper
return function(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/socks.py", line 814, in connect
raise GeneralProxyError("Socket error", error)
socks.GeneralProxyError: Socket error: 0x01: General SOCKS server failure
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 841, in _validate_conn
conn.connect()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 301, in connect
conn = self._new_conn()
File "/usr/lib/python3/dist-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 0x7f7e011a15d0>: Failed to establish a new connection: 0x01: General SOCKS server failure
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: SOCKSHTTPSConnectionPool(host='www.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabgu.onion', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f7e011a15d0>: Failed to establish a new connection: 0x01: General SOCKS server failure'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pero/PycharmProjects/test/pythoin/test1.py", line 21, in <module>
print(session.get(url).text)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 546, in get
return self.request('GET', url, **kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: SOCKSHTTPSConnectionPool(host='www.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabgu.onion', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7f7e011a15d0>: Failed to establish a new connection: 0x01: General SOCKS server failure'))
Я не поймите, что не так, если я использую тот же код для отправки запроса на 'https://www.facebookcorewwwi.onion/'
, он работает нормально и печатает html сайта.
Я не ожидаю, что ответ пройдет хорошо, но я ожидал что-то вроде Could not reach the host
или Response 403
.