gkiwi
V2EX  ›  Flask

用 Flask-login 来作登陆处理,经常(但不是一直)爆出未登录异常,求经验分享...

  •  
  •   gkiwi · Nov 27, 2014 · 3246 views
    This topic created in 4191 days ago, the information mentioned may be changed or developed.
    在局域网测试,一般都是ok的.但是以上服务器测试,手机的app就经常爆出这个问题.

    而在局域网内,app端更换自己的局域网ip **一定**会爆出这个问题,在此种情境下,我print 了cookies和session,发现都没变.

    大家是怎么处理这块的?
    谢谢.
    3 replies    2014-11-27 17:45:34 +08:00
    hahastudio
        1
    hahastudio  
       Nov 27, 2014
    没用过 Flask

    看文档的话
    https://flask-login.readthedocs.org/en/latest/#session-protection
    提到了默认是 basic
    glasslion
        2
    glasslion  
       Nov 27, 2014
    You can configure session protection on the LoginManager, and in the app’s configuration. If it is enabled, it can operate in either basic or strong mode. To set it on the LoginManager, set the session_protection attribute to "basic" or "strong":

    login_manager.session_protection = "strong"
    Or, to disable it:

    login_manager.session_protection = None
    By default, it is activated in "basic" mode. It can be disabled in the app’s configuration by setting the SESSION_PROTECTION setting to None, "basic", or "strong".

    When session protection is active, each request, it generates an identifier for the user’s computer (basically, the MD5 hash of the IP address and user agent). If the session does not have an associated identifier, the one generated will be stored. If it has an identifier, and it matches the one generated, then the request is OK.
    gkiwi
        3
    gkiwi  
    OP
       Nov 27, 2014
    @hahastudio
    @glasslion

    谢谢两位!仔细看了下,原来配置文件里面SESSION_PROTECTION被设置成了"strong"..

    非常感谢!!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5598 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 02:01 · PVG 10:01 · LAX 19:01 · JFK 22:01
    ♥ Do have faith in what you're doing.