使用python-social-auth,SqlAlchemy和Flask从Facebook登录重定向时出错

时间:2016-07-17 06:29:09

标签: python facebook flask sqlalchemy python-social-auth

我正在尝试使用python-social-auth在Flask中实现社交登录。它适用于localhost的开发,但不适用于生产。

从Facebook登录重定向时发生错误。调试后,它似乎是由sql类型的pickle或json中的解码引起的。我挖掘了json模块,但不知道如何修复它,我认为不应该修复它,因为它是一个内置模块。

为什么Facebook登录在localhost上开发但不在生产中?

Exception on /complete/facebook/ [GET]
Traceback (most recent call last):
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/social/apps/flask_app/utils.py", line 46, in wrapper
    return func(backend, *args, **kwargs)
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/social/apps/flask_app/routes.py", line 23, in complete
    *args, **kwargs)
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/social/actions.py", line 43, in do_complete
    user = backend.complete(user=user, *args, **kwargs)
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/social/backends/base.py", line 41, in complete
    return self.auth_complete(*args, **kwargs)
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/social/utils.py", line 229, in wrapper
    return func(*args, **kwargs)
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/social/backends/facebook.py", line 87, in auth_complete
    return self.do_auth(access_token, response, *args, **kwargs)
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/social/backends/facebook.py", line 119, in do_auth
    return self.strategy.authenticate(*args, **kwargs)
File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/social/backends/base.py", line 82, in authenticate
    return self.pipeline(pipeline, *args, **kwargs)
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/social/backends/base.py", line 85, in pipeline
    out = self.run_pipeline(pipeline, pipeline_index, *args, **kwargs)
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/social/backends/base.py", line 112, in run_pipeline
    result = func(*args, **out) or {}
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/social/pipeline/social_auth.py", line 20, in social_user
    social = backend.strategy.storage.user.get_social_auth(provider, uid)
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/social/storage/sqlalchemy_orm.py", line 136, in get_social_auth
    uid=uid)[0]
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2462, in __getitem__
    return list(self[item:item + 1])[0]
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2457, in __getitem__
    return list(res)
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/sqlalchemy/orm/loading.py", line 86, in instances
    util.raise_from_cause(err)
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 200, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/sqlalchemy/orm/loading.py", line 71, in instances
    rows = [proc(row) for row in fetch]
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/sqlalchemy/orm/loading.py", line 428, in _instance
    loaded_instance, populate_existing, populators)
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/sqlalchemy/orm/loading.py", line 486, in _populate_full
    dict_[key] = getter(row)
  File "/home/dev/huugbaan/xxvenv/lib/python2.7/site-packages/sqlalchemy/sql/sqltypes.py", line 1258, in process
    return loads(value)
  File "/usr/local/lib/python2.7.12/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python2.7.12/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer
[pid: 5053|app: 0|req: 6/26] 171.99.3.44 () {42 vars in 1892 bytes} [Sun Jul 17 02:09:00 2016] GET /complete/facebook/?redirect_state=i2C8teuxp7n3o39bhzK8Ypwa8S2O1EzC&code=AQBim0qoaEqukud-ysEQpuhyhy63v729wxqQ5qo3HTYRFSerzQrCgjXVKUu-EA1A1A5CXbAfzvZHb87K4moaxt0Wk4g5mhQQQ--ovb9NygFUybyznSk-09O8x-zB5CXSyFVR-fDV54CXSNbhBOJJvPWQu9rJ0QlGj53kEDFyKCgXA0-gHyLIXfDveY-3Z_nouWv0mosSogs9JSE06EQ9ZfZh87HKJkihEcnAs_QhO3eHhkZ5uqf7ZSWc-Soj2c4XXVEG38aR5Ltl-cv7tWkwAsKFtW36nBcF0NzEhDiuSYaiTIn-nZBnRBveO7PFrDJRj6GEts1tc9pY29KnZuA72YwN&state=i2C8teuxp7n3o39bhzK8Ypwa8S2O1EzC => generated 4571 bytes in 587 msecs (HTTP/1.1 500) 2 headers in 100 bytes (1 switches on core 0)

1 个答案:

答案 0 :(得分:0)

只需在sqlalchemy包的sqltype.py上进行脏修复 经过调试。我在下面的方法中找到了不同类型的值。所以我决定跳过并返回值,如果它已经是dict。

1245     def result_processor(self, dialect, coltype):
1246         impl_processor = self.impl.result_processor(dialect, coltype)
1247         loads = self.pickler.loads
1248         if impl_processor:
1249             def process(value):
1250                 value = impl_processor(value)
1251                 if value is None:
1252                     return None
1253                 return loads(value)
1254         else:
1255             def process(value):
1256                 if value is None:
1257                     return None
#### ->>>            if type(value) is dict: return value
1258                 return loads(value) 
1259         return process

if type(value) is dict: return value第1258行

相关问题