python-rtkit icon indicating copy to clipboard operation
python-rtkit copied to clipboard

Fix import on Python 3

Open tobiasge opened this issue 6 years ago • 3 comments

This changes fixes the import for cStringIO and ifilterfalse as intended by pull request #60. In this old pull request the import for ifilterfalse is tried in the wrong direction for Python 2 and 3.

tobiasge avatar Jan 29 '19 13:01 tobiasge

This would be a useful fix for us as well.

andreyyudin avatar Apr 18 '19 13:04 andreyyudin

Another issue has popped up and I have been wondering if you have it as well since you are adding support to Python 3:

  File "lib/python3.7/site-packages/rtkit/authenticators.py", line 127, in _login
    urllib2.Request(self.url, urlencode(data))
  File "lib/python3.7/urllib/request.py", line 523, in open
    req = meth(req)
  File "lib/python3.7/urllib/request.py", line 1247, in do_request_
    raise TypeError(msg)
TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.

This can be solved by changing urllib2.Request(self.url, urlencode(data))

to urllib2.Request(self.url, urlencode(data).encode('utf-8'))

andreyyudin avatar Apr 23 '19 15:04 andreyyudin

Oh and there is also a problem with unicode checks in rtkit/forms.py that can be solved by doing a check on Python version.

(perhaps, I should just make a pull request once I get rtkit working)

andreyyudin avatar Apr 25 '19 15:04 andreyyudin