joelverhagen / flask-rauth Goto Github PK
View Code? Open in Web Editor NEWAdds OAuth 1.0/a, 2.0, and Ofly consumer support for Flask.
License: Other
Adds OAuth 1.0/a, 2.0, and Ofly consumer support for Flask.
License: Other
access_token = resp.content.get('access_token')
AttributeError: 'function' object has no attribute 'get'
Commented out the content() override in RauthResponse and everything works. I am using python 2.7 and OAuth2. Took me a while to wire up pycharm and confirm. Just as I step into the if, it changes from a member variable to an instance function...not sure why though.
For now I will forgoe the caching...
When using the current PyPI release of flask-rauth, I get the following exception:
14:07:15 web.1 | Traceback (most recent call last):
14:07:15 web.1 | File "app.py", line 1, in <module>
14:07:15 web.1 | from qwake import run
14:07:15 web.1 | File "/Users/lvh/Code/qwake/qwake/__init__.py", line 57, in <module>
14:07:15 web.1 | access_token_url='https://connect.stripe.com/oauth/token',
14:07:15 web.1 | File "/Users/lvh/Code/qwake/venv/lib/python2.7/site-packages/flask_rauth.py", line 266, in __init__
14:07:15 web.1 | OAuth2Service.__init__(self, consumer_key=consumer_key, consumer_secret=consumer_secret, **kwargs)
14:07:15 web.1 | File "/Users/lvh/Code/qwake/venv/lib/python2.7/site-packages/rauth/service.py", line 318, in __init__
14:07:15 web.1 | if None in (self.consumer_key, self.consumer_secret):
14:07:15 web.1 | File "/Users/lvh/Code/qwake/venv/lib/python2.7/site-packages/flask_rauth.py", line 210, in consumer_key
14:07:15 web.1 | elif self.app is not None and self._consumer_key_config() in self.app.config:
14:07:15 web.1 | AttributeError: 'RauthOAuth2' object has no attribute 'app'
14:07:15 web.1 | exited with code 1
The required keys are in app.config
, but this is never read, because self.app
is set in RauthServiceMixin.__init__
:
https://github.com/joelverhagen/flask-rauth/blob/master/flask_rauth.py#L155
Which is called after OAuth2Service.__init__
:
https://github.com/joelverhagen/flask-rauth/blob/master/flask_rauth.py#L270
So I get the exception raised here:
https://github.com/joelverhagen/flask-rauth/blob/master/flask_rauth.py#L213
....
I worked around this issue by specifying these values when creating the object instead of putting them in the config, but the documentation suggests that isn't recommended. Anyway, I think the current_app using line isn't actually ever used, since the only case where it'd be used is when self.app isn't set yet...
Installed flask-rauth with pip. Seems to have installed:
Flask_Rauth-0.3.2-py2.7.egg
rauth-0.5.1-py2.7.egg
However the rauth api changed as of litl/rauth@bad9531 so that Response has been removed from service.py
File "/sw/myprog/prog.py", line 4, in
from flask_rauth import RauthOAuth2
File "/sw/myprog/env/local/lib/python2.7/site-packages/flask_rauth.py", line 17, in
from rauth.service import OAuth2Service, OAuth1Service, OflyService, Response, parse_utf8_qsl
ImportError: cannot import name Response
There is a Flask-OAuthlib: https://github.com/lepture/flask-oauthlib
Just FYI.
When I run this script:
#!/usr/bin/env python
from flask import Flask
from flask.ext.rauth import RauthOAuth2
app = Flask(__name__)
app.config.update(GITHUB_CONSUMER_KEY='foo', GITHUB_CONSUMER_SECRET='bar')
github = RauthOAuth2(
name='github',
base_url='https://api.github.com/',
authorize_url='https://github.com/login/oauth/authorize',
access_token_url='https://github.com/login/oauth/access_token',
)
if __name__ == '__main__':
app.run()
I get this error:
Traceback (most recent call last):
File "rautherr.py", line 13, in <module>
access_token_url='https://github.com/login/oauth/access_token',
File ".env/lib/python2.7/site-packages/flask_rauth.py", line 267, in __init__
OAuth2Service.__init__(self, consumer_key=consumer_key, consumer_secret=consumer_secret, **kwargs)
File ".env/lib/python2.7/site-packages/rauth/service.py", line 318, in __init__
if None in (self.consumer_key, self.consumer_secret):
File ".env/lib/python2.7/site-packages/flask_rauth.py", line 215, in consumer_key
return current_app.config.get(self._consumer_key_config(), None)
File ".env/lib/python2.7/site-packages/werkzeug/local.py", line 336, in __getattr__
return getattr(self._get_current_object(), name)
File ".env/lib/python2.7/site-packages/werkzeug/local.py", line 295, in _get_current_object
return self.__local()
File ".env/lib/python2.7/site-packages/flask/globals.py", line 26, in _find_app
raise RuntimeError('working outside of application context')
RuntimeError: working outside of application context
I expected it to at least instantiate so I could call github.init_app(app)
after that, as in the Twitter example. I tried to fix it by wrapping the instantiation in a with app.app_context():
, but that only changes the error to:
Traceback (most recent call last):
File "rautherr.py", line 14, in <module>
access_token_url='https://github.com/login/oauth/access_token',
File ".env/lib/python2.7/site-packages/flask_rauth.py", line 267, in __init__
OAuth2Service.__init__(self, consumer_key=consumer_key, consumer_secret=consumer_secret, **kwargs)
File ".env/lib/python2.7/site-packages/rauth/service.py", line 318, in __init__
if None in (self.consumer_key, self.consumer_secret):
File ".env/lib/python2.7/site-packages/flask_rauth.py", line 215, in consumer_key
return current_app.config.get(self._consumer_key_config(), None)
File ".env/lib/python2.7/site-packages/flask_rauth.py", line 242, in _consumer_key_config
return '%s_CONSUMER_KEY' % (self.name.upper(),)
AttributeError: 'RauthOAuth2' object has no attribute 'name'
As with issue #1, this seems related to the order in which the objects are configured in rauth 0.4.17. When initializing the RauthOAuth2
instance, OAuth2Service.__init__()
inadvertently calls back into the RauthServiceMixin.consumer_key
property. With no explicitly set app, it assumes it can look up the flask.current_app
and causes the RuntimeError
.
In the latter case, even if the app is set, the consumer_key
access happens before OAuth2Service.__init__()
calls the superimplementation to set the name
attribute, and RauthServiceMixin._consumer_key_config()
raises the AttributeError
.
Downgrading to rauth 0.4.16 causes the error not to occur. I only see it with rauth 0.4.17 and Flask-Rauth 0.3.2. As rauth 0.4.17's change is related to using client_id
instead of consumer_key
etc, this also seems to affect only OAuth2 services (specifically, flask-rauth's Twitter example still works).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.