Skip to content

OAuth import fails in Python 3.2 #944

Closed

Description

@sybrenstuvel

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 = None

Removing 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.

Activity

  1. Lukasa commented on Nov 18, 2012

    @Lukasa
    Member

    It's my understanding that the general intent is that requests will 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"?

  2. sybrenstuvel commented on Nov 18, 2012

    @sybrenstuvel
    Author
  3. Lukasa commented on Nov 18, 2012

    @Lukasa
    Member

    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.

  4. sybrenstuvel commented on Nov 18, 2012

    @sybrenstuvel
    Author

    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)

  5. Lukasa commented on Nov 18, 2012

    @Lukasa
    Member

    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.)

  6. sybrenstuvel commented on Nov 18, 2012

    @sybrenstuvel
    Author

    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 ;-)

  7. kennethreitz commented on Nov 18, 2012

    @kennethreitz
    Contributor

    That is indeed the plan.

  8. sybrenstuvel commented on Nov 19, 2012

    @sybrenstuvel
    Author

    @kennethreitz is the plan to fix it for 3.2, or to wait until Py3.3?

  9. kennethreitz commented on Nov 23, 2012

    @kennethreitz
    Contributor

    OAuthlib simply doesn't support Python 3 at this time.

  10. sybrenstuvel commented on Nov 23, 2012

    @sybrenstuvel
    Author

    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.

  11. kennethreitz commented on Nov 23, 2012

    @kennethreitz
    Contributor

    Ah, I'm a bit out of date!

    Let's do a new pull.

  12. kennethreitz commented on Nov 23, 2012

    @kennethreitz
    Contributor

    Fuck it, I'm extracting this out.

  13. sybrenstuvel commented on Nov 23, 2012

    @sybrenstuvel
    Author

    \o/

  14. Lukasa commented on Nov 23, 2012

    @Lukasa
    Member

    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.

  15. kennethreitz commented on Nov 23, 2012

    @kennethreitz
    Contributor

    Yeah, it'll be super simple. All the actual work is done by @idan and team :)

  16. sybrenstuvel commented on Nov 23, 2012

    @sybrenstuvel
    Author

    Yeah, I'm the maintainer of the Python Flickr API implementation, and they've moved to OAuth so I have no choice...

  17. kennethreitz commented on Nov 23, 2012

    @kennethreitz
    Contributor

    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.

  18. kennethreitz commented on Nov 23, 2012

    @kennethreitz
    Contributor

    Gah, not enough hours in a day, man.

  19. Lukasa commented on Nov 23, 2012

    @Lukasa
    Member

    @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.

  20. kennethreitz commented on Nov 23, 2012

    @kennethreitz
    Contributor

    @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

    ✨ 🍰 ✨

  21. sybrenstuvel commented on Nov 23, 2012

    @sybrenstuvel
    Author

    @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.

  22. Lukasa commented on Nov 23, 2012

    @Lukasa
    Member

    @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

  23. sybrenstuvel commented on Nov 23, 2012

    @sybrenstuvel
    Author

    Awesome!

  24. locked as resolved and limited conversation to collaborators on Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions