torpyorg / torpy

Pure python Tor client implementation
Apache License 2.0
411 stars 53 forks source link

Torpy not working on windows: socket.timeout: timed out / [WinError 10054] #20

Closed do-me closed 3 years ago

do-me commented 3 years ago

Torpy is not running anymore on Windows. The following minimal example always results in a timeout.

from torpy.http.requests import TorRequests
with TorRequests() as tor_requests:
    with tor_requests.get_session() as sess:
        response = sess.get("https://www.google.com/")
        print(response)

Returns:

timed out
ERROR:root:[ignored]
Traceback (most recent call last):
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\cell_socket.py", line 63, in connect
    self._socket.connect((self._router.ip, self._router.or_port))
  File "C:\Users\dome\Anaconda3\lib\ssl.py", line 1172, in connect
    self._real_connect(addr, False)
  File "C:\Users\dome\Anaconda3\lib\ssl.py", line 1159, in _real_connect
    super().connect(addr)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\utils.py", line 78, in newfn
    return func(*args, **kwargs)
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\consesus.py", line 163, in renew
    raw_string = self._authorities.download_consensus(prev_hash)
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\consesus.py", line 105, in download_consensus
    with TorGuard(authority) as guard:
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\guard.py", line 65, in __init__
    self.__tor_socket.connect()
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\cell_socket.py", line 69, in connect
    raise TorSocketConnectError(e)
torpy.cell_socket.TorSocketConnectError: timed out
WARNING:torpy.utils:Retry with another authority...
ERROR:torpy.cell_socket:timed out
ERROR:root:[ignored]
Traceback (most recent call last):
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\cell_socket.py", line 63, in connect
    self._socket.connect((self._router.ip, self._router.or_port))
  File "C:\Users\dome\Anaconda3\lib\ssl.py", line 1172, in connect
    self._real_connect(addr, False)
  File "C:\Users\dome\Anaconda3\lib\ssl.py", line 1159, in _real_connect
    super().connect(addr)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\utils.py", line 78, in newfn
    return func(*args, **kwargs)
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\consesus.py", line 175, in renew
    if not self.verify(new_doc):
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\consesus.py", line 200, in verify
    pubkey = self._get_pubkey(sign['identity'], sign['signing_key_digest'])
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\consesus.py", line 206, in _get_pubkey
    key_certificate = self._authorities.download_fp_sk(identity, signing_key_digest)
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\consesus.py", line 121, in download_fp_sk
    with TorGuard(authority) as guard:
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\guard.py", line 65, in __init__
    self.__tor_socket.connect()
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\cell_socket.py", line 69, in connect
    raise TorSocketConnectError(e)
torpy.cell_socket.TorSocketConnectError: timed out
WARNING:torpy.utils:Retry with another authority...
ERROR:torpy.cell_socket:timed out
ERROR:root:[ignored]
Traceback (most recent call last):
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\cell_socket.py", line 63, in connect
    self._socket.connect((self._router.ip, self._router.or_port))
  File "C:\Users\dome\Anaconda3\lib\ssl.py", line 1172, in connect
    self._real_connect(addr, False)
  File "C:\Users\dome\Anaconda3\lib\ssl.py", line 1159, in _real_connect
    super().connect(addr)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\utils.py", line 78, in newfn
    return func(*args, **kwargs)
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\consesus.py", line 163, in renew
    raw_string = self._authorities.download_consensus(prev_hash)
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\consesus.py", line 105, in download_consensus
    with TorGuard(authority) as guard:
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\guard.py", line 65, in __init__
    self.__tor_socket.connect()
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\cell_socket.py", line 69, in connect
    raise TorSocketConnectError(e)
torpy.cell_socket.TorSocketConnectError: timed out
WARNING:torpy.utils:Retry with another authority...
Traceback (most recent call last):
    self._socket.connect((self._router.ip, self._router.or_port))
  File "C:\Users\dome\Anaconda3\lib\ssl.py", line 1172, in connect
    self._real_connect(addr, False)
  File "C:\Users\dome\Anaconda3\lib\ssl.py", line 1159, in _real_connect
    super().connect(addr)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\http\requests.py", line 35, in __enter__
    self._tor = TorClient(auth_data=self._auth_data)
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\client.py", line 37, in __init__
    self._consensus = consensus or TorConsensus()
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\consesus.py", line 146, in __init__
    self.renew()
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\utils.py", line 78, in newfn
    return func(*args, **kwargs)
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\consesus.py", line 163, in renew
    raw_string = self._authorities.download_consensus(prev_hash)
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\consesus.py", line 105, in download_consensus
    with TorGuard(authority) as guard:
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\guard.py", line 65, in __init__
    self.__tor_socket.connect()
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\cell_socket.py", line 69, in connect
    raise TorSocketConnectError(e)
torpy.cell_socket.TorSocketConnectError: timed out

If on Jupyter, it returns the Windows Error code as well ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

do-me commented 3 years ago

Update: Working again but sometimes still displaying the same issue as in #19 : "unknown document received":

ERROR:root:[ignored]
Traceback (most recent call last):
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\utils.py", line 78, in newfn
    return func(*args, **kwargs)
  File "C:\Users\dome\Anaconda3\lib\site-packages\torpy\consesus.py", line 168, in renew
    raise Exception('Unknown document has been received')
Exception: Unknown document has been received
WARNING:torpy.utils:Retry with another authority...
ERROR:torpy.utils:[ignored] torpy.documents.network_status.FetchDescriptorError: Can't fetch descriptor from http://<someip>:8080/tor/server/fp/<somehash> 
WARNING:torpy.utils:Retry with another router...
do-me commented 3 years ago

Update 2: It's really odd, sometimes it's only working on Windows, sometimes only on Ubuntu. Does anyone have an idea where the OS differences come from?

FDenker commented 3 years ago

I have a newly setup windows 10 installation and it returns a very similar error when I run your code block:

ERROR:torpy.cell_socket:timed out
ERROR:root:[ignored]
Traceback (most recent call last):
  File "C:\Users\leond\anaconda3\lib\site-packages\torpy\cell_socket.py", line 63, in connect
    self._socket.connect((self._router.ip, self._router.or_port))
  File "C:\Users\leond\anaconda3\lib\ssl.py", line 1342, in connect
    self._real_connect(addr, False)
  File "C:\Users\leond\anaconda3\lib\ssl.py", line 1329, in _real_connect
    super().connect(addr)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\leond\anaconda3\lib\site-packages\torpy\utils.py", line 78, in newfn
    return func(*args, **kwargs)
  File "C:\Users\leond\anaconda3\lib\site-packages\torpy\consesus.py", line 152, in renew
    raw_string = self.download_consensus(prev_hash)
  File "C:\Users\leond\anaconda3\lib\site-packages\torpy\consesus.py", line 306, in download_consensus
    with self._get_auth_dir_client() as dir_client:
  File "C:\Users\leond\anaconda3\lib\site-packages\torpy\consesus.py", line 287, in _get_auth_dir_client
    return self._auth_dir_circuit.create_dir_client()
  File "C:\Users\leond\anaconda3\lib\site-packages\torpy\utils.py", line 60, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "C:\Users\leond\anaconda3\lib\site-packages\torpy\consesus.py", line 283, in _auth_dir_circuit
    self._auth_guard, circuit = self._create_dir_circuit(authority=True, purpose='Consensus/PublicKeys downloader')
  File "C:\Users\leond\anaconda3\lib\site-packages\torpy\consesus.py", line 278, in _create_dir_circuit
    guard = TorGuard(router, purpose=purpose)
  File "C:\Users\leond\anaconda3\lib\site-packages\torpy\guard.py", line 66, in __init__
    self.__tor_socket.connect()
  File "C:\Users\leond\anaconda3\lib\site-packages\torpy\cell_socket.py", line 69, in connect
    raise TorSocketConnectError(e)
torpy.cell_socket.TorSocketConnectError: timed out
WARNING:torpy.utils:Retry with another authority...
ERROR:root:[ignored]
Traceback (most recent call last):
  File "C:\Users\leond\anaconda3\lib\site-packages\torpy\utils.py", line 78, in newfn
    return func(*args, **kwargs)
  File "C:\Users\leond\anaconda3\lib\site-packages\torpy\consesus.py", line 171, in renew
    raise Exception('Invalid consensus')
Exception: Invalid consensus
WARNING:torpy.utils:Retry with another authority...
ERROR:root:[ignored]
Traceback (most recent call last):
  File "C:\Users\leond\anaconda3\lib\site-packages\torpy\utils.py", line 78, in newfn
    return func(*args, **kwargs)
  File "C:\Users\leond\anaconda3\lib\site-packages\torpy\consesus.py", line 171, in renew
    raise Exception('Invalid consensus')
Exception: Invalid consensus
WARNING:torpy.utils:Retry with another authority...

Does it currently work on Ubuntu for you?

do-me commented 3 years ago

Around 18 hours ago it only worked on Windows and not on Ubuntu. Otherwise until now I noticed it generally works better on Ubuntu (if it works at all). At the moment no OS is working for me.

jbrown299 commented 3 years ago

Because of errors and not optimal logic inside torpy tor authority server was under high traffic load. And was trying to block torpy. See https://gitlab.torproject.org/tpo/core/tor/-/issues/33018 for details.

445bc22 should fix this

SaadTazroute commented 1 year ago

do you guys still have the same issue ?

Artucuno commented 1 year ago

do you guys still have the same issue ?

Tor V2 is deprecated, this library won't work until it supports Tor V3