Python 3 support #47

Open
Daenyth opened this Issue Mar 8, 2011 · 18 comments

Comments

Projects
None yet
9 participants

Daenyth commented Mar 8, 2011

Is there any roadmap for python 3 support? I have some scripts that I might like to convert to py3k soon but are using restkit. I may be able to help somewhat with the translation, but I'm not sure if I can properly dedicate the time. Since it's pure python (as far as I can tell), it shouldn't take much effort to make it compatible.

Owner

benoitc commented Mar 19, 2011

Next release will be python3 compatible. Probably at the end of the month.

Owner

benoitc commented Apr 25, 2011

ok, finally got most of the bits to port restkit to py3. restkit will use http-parser in next release which support py3. net restkit will be online in 1 or 2 weeks with python3 support and somme enhancements. This version will also drop support for py2.5 .

@ghost ghost assigned benoitc Apr 25, 2011

Is there a status update on python 3 support ? I was thinking of hacking up a small program this weekend to learn python3 and was thinking of using restkit for REST stuff. (otherwise i'll just fall back to python2 and port when available)

Owner

benoitc commented Jun 19, 2011

available in 021104a .

I tried cloning 021104a and installing it, but when I import it in python3 there are a lot of errors. Exceptions still use python2 syntax and imported modules still use python2 names. Are you sure that's the right commit ?

Owner

benoitc commented Jun 20, 2011

you can't just import you need toiinstall it or patch it manually with
2to3 . work in progress anyway.

  • benoit

On Monday, June 20, 2011, gelendir
reply@reply.github.com
wrote:

I tried cloning 021104a and installing it, but when I import it in python3 there are a lot of errors. Exceptions still use python2 syntax and imported modules still use python2 names. Are you sure that's the right commit ?

Reply to this email directly or view it on GitHub:
#47 (comment)

Are you interested in using six (http://packages.python.org/six/) to make a version which doesn't need patching with 2to3? I've just done that for restpose-py, and it seemed a reasonable approach, though there may be harder issues to fix for restkit.

Scratch that comment - I see that installing does the 2to3 conversion - clever, and cunning.

I can't get it to work yet, though (though it does import ok once installed); may be I'm calling it wrong.

Owner

benoitc commented Jul 24, 2011

On Sunday, July 24, 2011, rboulton <
reply@reply.github.com>
wrote:

Scratch that comment - I see that installing does the 2to3 conversion -
clever, and cunning.

I can't get it to work yet, though (though it does import ok once
installed); may be I'm calling it wrong.

Reply to this email directly or view it on GitHub:
#47 (comment)

py3 version need some work. i'm currently refactoring the client to make it
happen.

  • benoit

Cool - I look forward to testing it.

gdamjan commented Sep 11, 2011

seems to install fine with Python 3 (3.2.2 here), but a demo that tries OAuth fails with:

  File "/home/damjan/py/lib/python3.2/site-packages/restkit/__init__.py", line 107, in request
    headers=headers)
  File "/home/damjan/py/lib/python3.2/site-packages/restkit/client.py", line 450, in request
    ret = f.on_request(request)
  File "/home/damjan/py/lib/python3.2/site-packages/restkit/filters.py", line 95, in on_request
    oauth_req.sign_request(self.method, self.consumer, self.token)
  File "/home/damjan/py/lib/python3.2/site-packages/restkit/oauth2.py", line 472, in sign_request
    self['oauth_body_hash'] = base64.b64encode(sha(self.body).digest())
TypeError: Unicode-objects must be encoded before hashing

the code is :

consumer = oauth.Consumer(consumer_key, consumer_secret)
token = oauth.Token(oauth_token, oauth_token_secret)
auth = OAuthFilter("*", consumer, token)

req = request('https://userstream.twitter.com/2/user.json', filters=[auth])

gdamjan commented Sep 11, 2011

regarding the last exception, it seems to be created by several occurences of body='' which is not translated by 2to3.
Maybe it should be replaced with body=bytes() (or body=None, and then change it in the code).
bytes() is available in 2.6, 2.7 and 3.2, didn't check others.

Hi, when will be ready py3 support?

Owner

benoitc commented Feb 24, 2013

sometimes next week. i've most of the tests passing on a test branch here, but I need to do a small refactoring first.

@benoitc thank you, if you need any help please let me know I am using restkit as base of one project.

restkit seems to work in Python 3 if I run 2to3 manually, but when I install restkit from PyPI that doesn't happen – should it? (I don't see any 2to3 setup in setup.py)

ari3s commented Jul 25, 2016

There is the 3 years old version of restkit on PyPI. Please, do you consider to finalize Python 3 version, and update PyPI?

dniq commented Jul 11, 2017

The py3 support actually only requires a few things to be done, it seems:

  1. Search cStringIO or StringIO import and replace with "from io import StringIO"
  2. Replace "import urlparse" with "from urllib.parse import urlparse"
  3. Ditto for import urlunparse, parse_qs and parse_qsl
  4. Search all "except" statements and replace comma with " as ".

Haven't actually tested this yet, but import is no longer failing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment