2016-07-17 46 views
1

我正嘗試使用python-social-auth在Flask中實現社交登錄。它在本地主機的開發中工作,但不在生產中。當從Facebook登錄使用python-social-auth,SqlAlchemy和Flask重定向時出錯

從Facebook登錄重定向時發生此錯誤。調試後,它似乎是由sql type pickle或json中的解碼引起的。我鑽進了json模塊,但不知道如何解決它,我認爲它不應該在那裏修復,因爲它是一個內置模塊。

爲什麼Facebook登錄在本地主機上的開發工作,但不是在生產?

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) 

回答

0

只是做骯髒固定在SQLAlchemy的包 的sqltype.py調試後。我在下面的方法中發現了不同的價值類型。所以我決定跳過並返回值,如果它已經是字典。

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