Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a working OAuth library for Python 3?

What's the most current form of Oauth for Python 3?

I'm trying to create a stock screener using my broker's API, which uses Oauth. Most of the info I find is out of date or conflicting. I've seen the following modules referenced:

Oauth - Seems to be the original, now outdated. I get an error of "'module' object has no attribute 'Consumer'"

Oauth2 - Newer version, apparently also outdated? The one most referenced one online. Glitches out in pip/can't figure out how to install it.

Oauthlib - IIRC, claims to be the new replacement for Oauth and Oauth2

Rauth.OAuth2Service - Also potentially replacement for Oauth and Oauth2?

Requests - ?

Oauth_hook - ?

pyoauth2 - I get an error about not having a module named "client" in pyoauth2's init.

None of them seem to work as expected, and I have a feeling that this is due to low Oauth 3 support. Have you gotten OAuth to work in Python 3? If so, how did you do it?

like image 966
Turtles Are Cute Avatar asked Apr 06 '13 15:04

Turtles Are Cute


2 Answers

It looks like Requets_oauthlib works. Here's code I used that works in Python 3. I'm posting it because most of the example code I found used formats that I couldn't get working.

from requests_oauthlib import OAuth1    

client_key = ''
client_secret = ''
resource_owner_key = ''
resource_owner_secret = ''

def query(queryurl):
        headeroauth = OAuth1(client_key, client_secret, resource_owner_key,
        resource_owner_secret, signature_type = 'auth_header')

        return requests.get(queryurl, auth = headeroauth)

query('http://website.com')
like image 63
Turtles Are Cute Avatar answered Oct 14 '22 15:10

Turtles Are Cute


Author of rauth here: rauth is a client library which currently does not officially support Python 3.

However, we are working on it, and there's an active branch (aptly named "python-3") over at GitHub which works. You're free to use it, but bear in mind that things may change slightly when we officially release support for it later on. With that said, it would be great to have people out in the real world testing it so that we can make changes to accommodate the Python 3 ecosystem.

Also note: oauthlib is not a replacement for rauth and not a client library. It attempts to be a generic solution, much like python-oauth2 was, but it doesn't provide a client, unlike python-oauth2.

like image 30
maxcountryman Avatar answered Oct 14 '22 13:10

maxcountryman