简体   繁体   English

是否有适用于Python 3的OAuth库?

[英]Is there a working OAuth library for Python 3?

What's the most current form of Oauth for Python 3? Python 3的最新形式的Oauth是什么?

I'm trying to create a stock screener using my broker's API, which uses Oauth. 我正在尝试使用我的经纪人API创建一个股票筛选器,它使用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. Oauth - 似乎是原始的,现在已经过时了。 I get an error of "'module' object has no attribute 'Consumer'" 我得到一个错误“'模块'对象没有属性'消费者'”

Oauth2 - Newer version, apparently also outdated? Oauth2 - 较新的版本,显然也已过时了? 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 Oauthlib - IIRC声称是Oauth和Oauth2的新替代品

Rauth.OAuth2Service - Also potentially replacement for Oauth and Oauth2? Rauth.OAuth2Service - 也可能替代Oauth和Oauth2?

Requests - ? 要求 - ?

Oauth_hook - ? Oauth_hook - ?

pyoauth2 - I get an error about not having a module named "client" in pyoauth2's init. pyoauth2 - 我在pyoauth2的init中没有一个名为“client”的模块时收到错误。

None of them seem to work as expected, and I have a feeling that this is due to low Oauth 3 support. 他们似乎没有按预期工作,我觉得这是由于Oauth 3支持率低。 Have you gotten OAuth to work in Python 3? 你有没有让OAuth在Python 3中工作? If so, how did you do it? 如果是这样,你是怎么做到的?

It looks like Requets_oauthlib works. 它看起来像Requets_oauthlib工作。 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. 这里我使用的代码在Python 3中工作。我发布它是因为我发现的大多数示例代码都使用了我无法工作的格式。

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

Author of rauth here: rauth is a client library which currently does not officially support Python 3. rauth的作者:rauth是一个客户端库,目前还没有正式支持Python 3。

However, we are working on it, and there's an active branch (aptly named "python-3") over at GitHub which works. 但是,我们正在研究它,并且在GitHub上有一个活动分支 (恰当地命名为“python-3”)。 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. 有了这样说,让人们在现实世界中测试它以便我们可以进行更改以适应Python 3生态系统将会很棒。

Also note: oauthlib is not a replacement for rauth and not a client library. 另请注意:oauthlib不是rauth的替代品,也不是客户端库的替代品。 It attempts to be a generic solution, much like python-oauth2 was, but it doesn't provide a client, unlike python-oauth2. 它试图成为一个通用的解决方案,就像python-oauth2一样,但与python-oauth2不同,它不提供客户端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM