JohnDoee / deluge-client

A very lightweight pure-python Deluge RPC Client
MIT License
87 stars 14 forks source link

Python 3.10 SSL Error #44

Closed mdhiggins closed 6 months ago

mdhiggins commented 2 years ago

Looks like due to SSL deprecations and/or changes to default ciphers this no longer works on Python 3.10

Attempts to connect are met with

>>> client.connect()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\tehps\AppData\Local\Programs\Python\Python310\lib\site-packages\deluge_client\client.py", line 84, in connect
    self._connect()
  File "C:\Users\tehps\AppData\Local\Programs\Python\Python310\lib\site-packages\deluge_client\client.py", line 98, in _connect
    self._socket.connect((self.host, self.port))
  File "C:\Users\tehps\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1374, in connect
    self._real_connect(addr, False)
  File "C:\Users\tehps\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1365, in _real_connect
    self.do_handshake()
  File "C:\Users\tehps\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1341, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:997)

If I set a cipher in client.py in the _create_socket method this seems to fix things

    def _create_socket(self, ssl_version=None, ciphers="AES256-SHA"):
        if ssl_version is not None:
            self._socket = ssl.wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM), ssl_version=ssl_version, ciphers=ciphers)
        else:
            self._socket = ssl.wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM), ciphers=ciphers)
        self._socket.settimeout(self.timeout)
colutti commented 2 years ago

Same problem here on fedora and python 3.10.3

mdhiggins commented 2 years ago

Not sure how active development is on this project but I was able to get things working temporarily by subclassing and fixing this one method, sample below

# Fix for python 3.10 SSL issues
class SMADelugeRPCClient(DelugeRPCClient):
    def _create_socket(self, ssl_version=None):
        if ssl_version is not None:
            self._socket = ssl.wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM), ssl_version=ssl_version, ciphers="AES256-SHA")
        else:
            self._socket = ssl.wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM), ciphers="AES256-SHA")
        self._socket.settimeout(self.timeout)

...
client = SMADelugeRPCClient(host=settings.deluge['host'], port=int(settings.deluge['port']), username=settings.deluge['user'], password=settings.deluge['pass'])

Reference: https://github.com/mdhiggins/sickbeard_mp4_automator/blob/master/delugePostProcess.py

bjorgvinhall commented 1 year ago

@mdhiggins this worked for me, thank you!

JohnDoee commented 6 months ago

I've tried to do a fallback fix but SSL is hard.