Repository navigation
Closed
Description
I'm trying out Request's OAuth support on Python 3.2. The following code:
import requests
from requests.auth import OAuth1
url = 'https://api.twitter.com/1/account/settings.json'
queryoauth = OAuth1('client_key', 'client_secret',
'resource_owner_key', 'resource_owner_secret',
signature_type='query')
r = requests.get(url, auth=queryoauth)gives me this error:
Traceback (most recent call last):
File "simple_oauth_test.py", line 8, in <module>
signature_type='query')
File "/home/sybren/.virtualenvs/flickrapi-py32/lib/python3.2/site-packages/requests-0.14.1-py3.2.egg/requests/auth.py", line 68, in __init__
self.client = Client(client_key, client_secret, resource_owner_key,
NameError: global name 'Client' is not defined
requests/auth.py contains the following:
try:
from ._oauth import (Client, SIGNATURE_HMAC, SIGNATURE_TYPE_AUTH_HEADER, extract_params)
except (ImportError, SyntaxError):
SIGNATURE_HMAC = None
SIGNATURE_TYPE_AUTH_HEADER = NoneRemoving the try/except clause to show the actual import error gives me this:
Traceback (most recent call last):
File "/home/sybren/.virtualenvs/flickrapi-py32/lib/python3.2/site-packages/requests-0.14.1-py3.2.egg/requests/_oauth.py", line 15, in <module>
from oauthlib.oauth1 import rfc5849
ImportError: No module named oauthlib.oauth1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "simple_oauth_test.py", line 1, in <module>
import requests
File "/home/sybren/.virtualenvs/flickrapi-py32/lib/python3.2/site-packages/requests-0.14.1-py3.2.egg/requests/__init__.py", line 53, in <module>
from .models import Request, Response
File "/home/sybren/.virtualenvs/flickrapi-py32/lib/python3.2/site-packages/requests-0.14.1-py3.2.egg/requests/models.py", line 19, in <module>
from .auth import HTTPBasicAuth, HTTPProxyAuth
File "/home/sybren/.virtualenvs/flickrapi-py32/lib/python3.2/site-packages/requests-0.14.1-py3.2.egg/requests/auth.py", line 22, in <module>
from ._oauth import (Client, SIGNATURE_HMAC, SIGNATURE_TYPE_AUTH_HEADER, extract_params)
File "/home/sybren/.virtualenvs/flickrapi-py32/lib/python3.2/site-packages/requests-0.14.1-py3.2.egg/requests/_oauth.py", line 22, in <module>
from oauthlib.oauth1 import rfc5849
File "/home/sybren/.virtualenvs/flickrapi-py32/lib/python3.2/site-packages/requests-0.14.1-py3.2.egg/requests/packages/oauthlib/oauth1/__init__.py", line 12, in <module>
from .rfc5849 import Client, Server
File "/home/sybren/.virtualenvs/flickrapi-py32/lib/python3.2/site-packages/requests-0.14.1-py3.2.egg/requests/packages/oauthlib/oauth1/rfc5849/__init__.py", line 22
SIGNATURE_HMAC = u"HMAC-SHA1"
^
SyntaxError: invalid syntax
String literals with a u-prefix are not supported for Python 3.x before 3.3. Since the largest install base of 3.x still runs on 3.2 (I'm assuming, given the recent release date of 3.3) it would be very nice if we could use OAuth on Python 3.2.
Metadata
Metadata
Assignees
Labels
No labels
Activity
Lukasa commentedon Nov 18, 2012
It's my understanding that the general intent is that
requestswill stop supporting Python 3.2 and move to supporting Python 3.3, in no small part because of this syntax.@kennethreitz, do you want this to be fixed now, or should we just leave this until it fixes itself in 3.3 and so consider this a "won't fix"?
sybrenstuvel commentedon Nov 18, 2012
According to http://docs.python-requests.org/en/latest/community/faq/#python-3-support Python 3.1 and 3.2 are officially supported, so I'm a little taken aback by this response.
Lukasa commentedon Nov 18, 2012
Taken aback by which part? =)
I didn't say I wouldn't fix it, I asked Kenneth what he wanted to do. He may (and probably will) say that it should be fixed. The reason I asked is that I know he's expressed a desire to stop supporting 3.1 and 3.2 in the past (because of how much easier it is to support 3.3), and if he was planning to do that in the near future then I could better spend my time fixing things that will still be bugs in 3.3.
Requests is still pre-version 1.0, and support for previous versions is withdrawn from time-to-time. Requests used to support Python 2.5, now it doesn't. In fact, I'm startled that we claim to support 3.1, because we haven't been testing on 3.1 for quite some time, and so we could easily have broken something.
The question is not whether we want the bug fixed: we do. The question is whether we treat it as a priority. If someone else (yourself, for instance) supplied a Pull Request with the fix, it'd almost certainly be accepted, and I encourage you to do just that.
EDIT: In fact, we have an outstanding Python 3.1 bug too, in the form of #882.
sybrenstuvel commentedon Nov 18, 2012
Ah, that clarifies things, thanks. I'll see if I can fix this for you, but first I have to get my own code in working order (I'm changing the Python FlickrAPI client from the old authentication method to OAuth)
Lukasa commentedon Nov 18, 2012
Sounds good. =)
While we're on the OAuth topic, I'd like to draw your attention to #938. Based on the way Requests is moving, I suspect that the OAuth support will end up being pulled out of the main Requests trunk and into a new module, much like the Kerberos and NTLM stuff. I doubt this will happen in the immediate future, but certainly in the medium term. (In case you're interested, part of the reason is that we don't have much in the way of tests for the authentication stuff, and keeping them in their own modules makes it easier to do testing.)
sybrenstuvel commentedon Nov 18, 2012
I'll keep an eye on that, thanks. So far Requests has been amazingly easy to work with, so you won't loose me any time soon ;-)
kennethreitz commentedon Nov 18, 2012
That is indeed the plan.
sybrenstuvel commentedon Nov 19, 2012
@kennethreitz is the plan to fix it for 3.2, or to wait until Py3.3?
kennethreitz commentedon Nov 23, 2012
OAuthlib simply doesn't support Python 3 at this time.
sybrenstuvel commentedon Nov 23, 2012
According to http://pypi.python.org/pypi/oauthlib all their Python 3 tests pass since version 0.3.2, so apparently Python 3 is supported. Their "Support Python 3" issue #55 was closed a month ago.
So as far as supporting Python 3 goes, I think this particular issue is far from closed.
kennethreitz commentedon Nov 23, 2012
Ah, I'm a bit out of date!
Let's do a new pull.
kennethreitz commentedon Nov 23, 2012
Fuck it, I'm extracting this out.
sybrenstuvel commentedon Nov 23, 2012
\o/
kennethreitz commentedon Nov 23, 2012
https://github.com/requests/requests-oauthlib
Lukasa commentedon Nov 23, 2012
Had to be done, I just didn't want to be the one to do it because @kennethreitz might make me maintain it. The idea of working with OAuth keeps me up at night.
kennethreitz commentedon Nov 23, 2012
Yeah, it'll be super simple. All the actual work is done by @idan and team :)
sybrenstuvel commentedon Nov 23, 2012
Yeah, I'm the maintainer of the Python Flickr API implementation, and they've moved to OAuth so I have no choice...
kennethreitz commentedon Nov 23, 2012
I'll update the built in version first though. I won't rip it out until 1.0.
I really need to work on that.
kennethreitz commentedon Nov 23, 2012
Gah, not enough hours in a day, man.
Lukasa commentedon Nov 23, 2012
@sybrenstuvel: Sucks to be you. =D
@kennethreitz: Mm, there's a lot on your plate. I tried to go through and close a few issues last week, because it had gotten a bit out of control. ATM I'm trying to triage new issues so I can keep the trivial ones off your radar.
kennethreitz commentedon Nov 23, 2012
@Lukasa you're doing an absolutely kick-ass job, and you've made this project twice as sustainable as it already was. This Thanksgiving, I'm thankful for you :P
✨ 🍰 ✨
sybrenstuvel commentedon Nov 23, 2012
@Lukasa haha thanks :P
@kennethreitz and @Lukasa thank you both for the great lib! My work has become a lot easier thanks to you guys.
Lukasa commentedon Nov 23, 2012
@sybrenstuvel: In all seriousness, I run around, patch small holes, close issues and write docs. The general awesomeness of this library was in place before I got to this project, I'm just basking in reflected glory. =)
@kennethreitz: Thanks Kenneth, always affirming to know that my contribution is valuable. =D This thanksgiving (and the one before, and the one before that...) I'm thankful for your ludicrous productivity. If I was half as productive as you I'd be way better paid. =P
kennethreitz commentedon Nov 23, 2012
Released! https://github.com/requests/requests-oauthlib
sybrenstuvel commentedon Nov 23, 2012
Awesome!