使用 openshift 的 flask dropbox 快速入门示例
flask dropbox quick start example with openshift
我无法在 openshift 平台上成功执行来自 http://flask-dance.readthedocs.org/en/latest/quickstarts/dropbox.html 的示例。
from flask import Flask, redirect, url_for
from flask_dance.contrib.dropbox import make_dropbox_blueprint, dropbox
app = Flask(__name__)
app.secret_key = "supersekrit"
blueprint = make_dropbox_blueprint(
app_key="my-key-here",
app_secret="my-secret-here",
)
app.register_blueprint(blueprint, url_prefix="/login")
@app.route("/")
def index():
if not dropbox.authorized:
return redirect(url_for("dropbox.login"))
resp = dropbox.get("account/info")
assert resp.ok
return "You are {email} on Dropbox".format(email=resp.json()["email"])
if __name__ == "__main__":
app.run()
我遇到传输错误(openshift 尝试使用 HTTP uri 而不是 HTTPS),或者如果我尝试设置
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
(我知道出于安全考虑不推荐这样做)然后我得到
InvalidClientIdError: (invalid_request) Can't use "Authorization"
header and "client_secret" arg together.
在本地和 openshift 平台上。
对上面示例中的调整内容有什么建议吗?
您是否熟悉如何在 openshift 上部署基本的 flask 应用程序。这里有一份link到官方openshift文档https://developers.openshift.com/en/python-flask.html and here https://github.com/openshift-quickstart/flask-base。一旦你启动了你的 openshift flask-base 应用程序并且 运行 然后你可以通过 virtualenv 添加额外的 dropbox 模块来增强它。当您从 openshift 示例成功部署应用程序并运行时,然后通过将依赖项放入 setup.py:
来使用额外的 Flask-Dance 扩展它
from setuptools import setup
setup(name='FlaskApp',
version='1.0',
description='A basic Flask app with static files',
author='Ryan Jarvinen',
author_email='ryanj@redhat.com',
url='http://www.python.org/sigs/distutils-sig/',
install_requires=['Flask>=0.10.1','Flask-Dance'],
)
然后在 flaskapp.py 中使用它,就像在您的保管箱指南 http://flask-dance.readthedocs.org/en/latest/quickstarts/dropbox.html 中的示例中所做的那样。
I'm getting either a transport error (openshift tries to use HTTP uri
instead of HTTPS)
尝试访问 https://yourApp-namespace.rhcloud.com
上的索引(不是 http)并确保它已为您的 Dropbox 应用配置为重定向 URI 之一。
如果这不起作用,您可以查看 OpenShift 上提供的 this. However, the tutorial code works for me with the flask quick-start。 flaskapp.py
(即 app.config.from_pyfile('flaskapp.cfg')
)中必须引用应用配置,此外还有您在上面链接和发布的代码。
我无法在 openshift 平台上成功执行来自 http://flask-dance.readthedocs.org/en/latest/quickstarts/dropbox.html 的示例。
from flask import Flask, redirect, url_for
from flask_dance.contrib.dropbox import make_dropbox_blueprint, dropbox
app = Flask(__name__)
app.secret_key = "supersekrit"
blueprint = make_dropbox_blueprint(
app_key="my-key-here",
app_secret="my-secret-here",
)
app.register_blueprint(blueprint, url_prefix="/login")
@app.route("/")
def index():
if not dropbox.authorized:
return redirect(url_for("dropbox.login"))
resp = dropbox.get("account/info")
assert resp.ok
return "You are {email} on Dropbox".format(email=resp.json()["email"])
if __name__ == "__main__":
app.run()
我遇到传输错误(openshift 尝试使用 HTTP uri 而不是 HTTPS),或者如果我尝试设置
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
(我知道出于安全考虑不推荐这样做)然后我得到
InvalidClientIdError: (invalid_request) Can't use "Authorization" header and "client_secret" arg together.
在本地和 openshift 平台上。
对上面示例中的调整内容有什么建议吗?
您是否熟悉如何在 openshift 上部署基本的 flask 应用程序。这里有一份link到官方openshift文档https://developers.openshift.com/en/python-flask.html and here https://github.com/openshift-quickstart/flask-base。一旦你启动了你的 openshift flask-base 应用程序并且 运行 然后你可以通过 virtualenv 添加额外的 dropbox 模块来增强它。当您从 openshift 示例成功部署应用程序并运行时,然后通过将依赖项放入 setup.py:
来使用额外的 Flask-Dance 扩展它from setuptools import setup
setup(name='FlaskApp',
version='1.0',
description='A basic Flask app with static files',
author='Ryan Jarvinen',
author_email='ryanj@redhat.com',
url='http://www.python.org/sigs/distutils-sig/',
install_requires=['Flask>=0.10.1','Flask-Dance'],
)
然后在 flaskapp.py 中使用它,就像在您的保管箱指南 http://flask-dance.readthedocs.org/en/latest/quickstarts/dropbox.html 中的示例中所做的那样。
I'm getting either a transport error (openshift tries to use HTTP uri instead of HTTPS)
尝试访问 https://yourApp-namespace.rhcloud.com
上的索引(不是 http)并确保它已为您的 Dropbox 应用配置为重定向 URI 之一。
如果这不起作用,您可以查看 OpenShift 上提供的 this. However, the tutorial code works for me with the flask quick-start。 flaskapp.py
(即 app.config.from_pyfile('flaskapp.cfg')
)中必须引用应用配置,此外还有您在上面链接和发布的代码。