JohnDoee / deluge-client

A very lightweight pure-python Deluge RPC Client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exceptions on python 3 with decode_utf8=True

gazpachoking opened this issue · comments

Seems if the client is set to decode utf8 already, we have a problem creating an exception returned from deluge:

Traceback (most recent call last):
  File "C:/Users/Chase/PycharmProjects/deluge-client/test.py", line 7, in <module>
    print(a.call('core.get_free_space', '2', '3'))
  File "C:\Users\Chase\PycharmProjects\deluge-client\deluge_client\client.py", line 197, in call
    return self._receive_response(self.deluge_version)
  File "C:\Users\Chase\PycharmProjects\deluge-client\deluge_client\client.py", line 173, in _receive_response
    exception = type(str(exception_type.decode('utf-8', 'ignore')), (Exception, ), {})
AttributeError: 'str' object has no attribute 'decode'

I guess my first question before working on a fix is: Do we need to make decode_utf8 be optional? My feeling is that text should be text, on both python 2 and 3 automatically. (i.e. py2 unicode, py3 str)

I have some torrents with invalid utf-8 in them, I'll test with them and see how it's handled.

You're probably right that it doesn't make sense as an option if everything can be decoded.

... the double decoding is, of course, a bug.

Although it's not the biggest of libraries, I want to do proper deprecation.

The only way I could find without breaking stuff on a release is to do it in two stages

  • First make users to set decode_utf8=True
  • Second make users to remove it completely

What do you think about that ?
It feels like a lot of work though, to do it in two stages.

My suggestion is in #25

Yeah, seems like a plan to me. Made a PR against your PR branch with some more tests.