在 PythonAnywhere 上使用 Flask-Stormpath 登录 Facebook 引发 JSONDecodeError

Logging in with Facebook using Flask-Stormpath on PythonAnywhere raises JSONDecodeError

我正在尝试在 PythonAnywhere 上部署我的应用程序,但我无法设置 Flask-Stormpath Facebook 登录。

基于电子邮件的登录和 Google 连接工作正常,但 Facebook 登录无效。我已将 Facebook 应用程序更新为正确的应用程序 url 并验证 Facebook connect 确实可以在本地主机上运行。

2016-04-14 18:08:07,121 :Exception on /facebook [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1687, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1360, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1358, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1344, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/btpraasta/.local/lib/python2.7/site-packages/flask_stormpath/views.py", line 265, in facebook_login
    current_app.config['STORMPATH_SOCIAL']['FACEBOOK']['app_secret'],
  File "/usr/local/lib/python2.7/dist-packages/facebook.py", line 497, in get_user_from_cookie
    app_id, app_secret)
  File "/usr/local/lib/python2.7/dist-packages/facebook.py", line 581, in get_access_token_from_code
    response = json.loads(response)
  File "/usr/local/lib/python2.7/dist-packages/simplejson/__init__.py", line 488, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python2.7/dist-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/local/lib/python2.7/dist-packages/simplejson/decoder.py", line 389, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
JSONDecodeError: Expecting value: line 1 column 1 (char 0)

这是我正在使用的 StormPath 配置:-

# Stormpath app configuration
app.config['STORMPATH_API_KEY_FILE'] = '/home/btpraasta/btp_raasta/stormpath/apiKey.properties'
app.config['STORMPATH_API_KEY_FILE'] = 'stormpath/apiKey.properties'
app.config['STORMPATH_APPLICATION'] = 'Raasta'
app.config['STORMPATH_REDIRECT_URL'] = '/redirecting'
app.config['STORMPATH_REGISTRATION_REDIRECT_URL'] = '/verifyEmail'
app.config['STORMPATH_REGISTRATION_TEMPLATE'] = 'register.html'
app.config['STORMPATH_LOGIN_TEMPLATE'] = 'login.html'
app.config['STORMPATH_FORGOT_PASSWORD_TEMPLATE'] = 'forgot.html'
app.config['STORMPATH_ENABLE_MIDDLE_NAME'] = False
app.config['STORMPATH_ENABLE_USERNAME'] = True
app.config['STORMPATH_REQUIRE_USERNAME'] = True
app.config['STORMPATH_ENABLE_FORGOT_PASSWORD'] = True
app.config['STORMPATH_ENABLE_FACEBOOK'] = True
app.config['STORMPATH_ENABLE_GOOGLE'] = True
app.config['STORMPATH_SOCIAL'] = {
    'FACEBOOK': {
        'app_id': 'xxxxx',
        'app_secret': 'xxxxx',
    },
    'GOOGLE': {
        'client_id': 'xxxxx',
        'client_secret': 'xxxxxx',
    }
}

client_id 和 client_secret 已被隐藏。相同的配置在本地主机上工作。

错误是由于 Facebook-SDK 版本 0.4 没有输出代理支持。提出了一个勾选,现在 Flask-Stormpath 使用支持相同的 Facebook-SDK 1.0 版。

如果您仍然遇到同样的问题,请更新您的 Flask-Stormpath :-

pip install --upgrade flask-stormpath